3

I am using scale_colour_manual to specify the possible colors I need. However, if I choose red I get the eye-burning red color rather than the milder ggplot2 default red that would appear if I didn't use scale_colour_manual in the first place. What are the labels or constants for accessing ggplot2 default color palette?

 ggplot(data=df, aes(x=n, y=rt, group=kernel, shape=kernel, colour=kernel)) + 
     geom_point(fill="white", size=3) + geom_line() + xlab("n") + ylab("Runtime (s)") + 
     opts(title=title,plot.title=theme_text(size=font.size)) + 
     scale_colour_manual(values=c("grey30", "red")) + 
     opts(legend.position = c(x_shift,0.87),legend.background=theme_rect(fill = "transparent",colour=NA))

Note that using 'red30' won't work, it only works for gray for some reason unknown to me.

Sandy Muspratt
  • 31,719
  • 12
  • 116
  • 122
SkyWalker
  • 13,729
  • 18
  • 91
  • 187

2 Answers2

4

red30 doesn't work, because there is no concept of having only thirty percent of a color, though there is the concept of having thirty percent of a shade of grey (i.e. 30% of the way between black and white.)

If you want a non eye-burning red with scale_color_manual you will need to specify colors in RGB, viz. by using three bytes to represent the red green and blue color in hexadecimal. Something like this should work

ggplot(data=df, aes(x=n, y=rt, group=kernel, shape=kernel, colour=kernel)) + 
 geom_point(fill="white", size=3) + geom_line() + xlab("n") + ylab("Runtime (s)") + 
 opts(title=title,plot.title=theme_text(size=font.size)) + 
 scale_colour_manual(values=c("grey30", "#EF8A62")) + 
 opts(legend.position = c(x_shift,0.87),legend.background=theme_rect(fill =  "transparent",colour=NA))

If you don't know about how to work with this sort of color coding refer to this. I don't know how to extract the colors ggplot uses programmatically, but you could always just load a plot you produced with the standard colors into some image editor (e.g. The Gimp) and find out what the exact color code is. You can find good color schemes on colorbrewer, but note that ggplot2 already has a function for those: scale_brewer.

Aleksandar Dimitrov
  • 9,275
  • 3
  • 41
  • 48
3

The default "pastel red" and "pastel blue" used in ggplot2 have hex codes of #f8766d and #00b0f6, respectively, and RGB codes 248,118,109 and 0,176,246, respectively. To specify these with scale_colour_manual:

scale_colour_manual(values=c("#f8766d", "#00b0f6"))
jlab
  • 252
  • 2
  • 18