我在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”调色板现在已删除,或者我是否需要任何先决条件设置才能使其对此代码有效?帮助我让它发挥作用。
答案 0 :(得分:1)
我怀疑你输错了#34; YIOrRd。"无论如何,在这里你可以找到所有的朋友名字:https://www.nceas.ucsb.edu/~frazier/RSpatialGuides/colorPaletteCheatsheet.pdf
答案 1 :(得分:0)
嗯,你犯了一个拼写错误。调色板名称为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")