Error using brewer.pal(9, "Y10rRd")

5.7k Views Asked by At

I'm having some problems with colour palettes in ggplot2. When I try the following code, an error is produced.

library(ggplot2)
> ggplot(Vocab, x = education, y = vocabulary, col = year, group = factor(year)) +
+     stat_quantile(method = "lm", se = F, alpha = 0.6, size = 2) +
+     scale_color_brewer(colors = brewer.pal(9, "Y10rRd"))
Warning: Ignoring unknown parameters: se
Error in brewer.pal(9, "Y10rRd") : 
  Y10rRd is not a valid palette name for brewer.pal

"Y10rRd" colour palette is removed nowadays or do I need any prerequisite settings to get it valid for this code? Help me to make it work.

2

There are 2 best solutions below

0
On BEST ANSWER

I suspect you made a typo "YIOrRd." In any case, here you may find all pal names: https://www.nceas.ucsb.edu/~frazier/RSpatialGuides/colorPaletteCheatsheet.pdf

0
On

Well, you made a typo error. The palette name is YlOrRd and not Y1OrRd See below a minimum reproducible example;

library(RColorBrewer)
library(ggplot2)

#  the display.brewer.all function will plot all of them along with their name.
display.brewer.all() 

plot(dist ~ speed, data=cars, pch=19, col=2)
ggplot(iris, aes(x=Sepal.Length, y=Petal.Length, color=Species)) + geom_point()+
  scale_color_brewer(palette = "YlOrRd")

Plot