使用 brewer.pal(9, "Y10rRd") 时出错

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

我在 ggplot2 中遇到调色板问题。当我尝试以下代码时,会产生错误。

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" 调色板如今已被删除,或者我是否需要任何先决条件设置才能使其对该代码有效?帮助我让它工作。

我怀疑你打错了"YIOrRd."无论如何,在这里你可以找到所有朋友的名字:https://www.nceas.ucsb.edu/~frazier/RSpatialGuides/colorPaletteCheatsheet.pdf

嗯,你打错了。调色板名称是 YlOrRd 而不是 Y1OrRd 请参阅下面的最小可重现示例;

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")