[R] selecting colors to be used in a plot

Bos, Roger roger.bos at rothschild.com
Wed Jan 25 18:44:59 CET 2017

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.

More information about the R-help mailing list