[R] selecting colors to be used in a plot
Richard M. Heiberger
rmh at temple.edu
Wed Jan 25 18:58:06 CET 2017
This package uses a nonstandard name colorset.
This is based on the help example for
> charts.PerformanceSummary(edhec[,c(1,13)], colorset=c("red","blue"))
On Wed, Jan 25, 2017 at 12:44 PM, Bos, Roger <roger.bos at rothschild.com> wrote:
> My specific question relates to function charts.PerformanceSummary in package PerformanceAnalytics, but the underlying problem is probably with base plot.
> In this sample code we see a chart with 10 groupings. Apparently 10 groupings is bigger than the number of default colors (8), so red and black are recycled, but in my case groups 1 and 2 are the worst and groups 9 and 10 are the best, so if the same red and black colors are used for both it gets confusing:
> Minimal working example with recycled colors:
> dates <- as.Date(c('1970-01-02','1970-01-03','1970-01-04','1970-01-05','1970-01-06','1970-01-07','1970-01-08','1970-01-09','1970-01-10','1970-01-11'), format="%Y-%m-%d")
> x <- as.xts(matrix(runif(100),10,10), order.by=dates)
> names(x) <- paste("Group", 1:10)
> charts.PerformanceSummary(x, geometric=FALSE, ylog=TRUE, main='Log Return by Column')
> Since the documentation says you can pass other variables to plot, I try to use “col” to set my own colors:
> colors <- c("#A6CEE3","#1F78B4","#B2DF8A","#33A02C","#FB9A99","#E31A1C","#FDBF6F","#FF7F00","#CAB2D6","#6A3D9A")
> charts.PerformanceSummary(x, geometric=FALSE, ylog=TRUE, col = colors, main='Log Return by Column')
> Error in plot.xy(xy.coords(x, y), type = type, ...) :
> formal argument "col" matched by multiple actual arguments
> I am sure it is possible to produce a plot using more than 8 colors. Would someone please point out what I am doing wrong? Thanks in advance.
> This message and any attachments are for the intended recipient’s use only. This message may contain confidential, proprietary or legally privileged information. No right to confidential or privileged treatment of this message is waived or lost by an error in transmission.
> If you have received this message in error, please immediately notify the sender by e-mail, delete the message, any attachments and all copies from your system and destroy any hard copies. You must not, directly or indirectly, use, disclose, distribute, print or copy any part of this message or any attachments if you are not the intended recipient.
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help