我想添加颜色到我的ggplot,但我似乎无法得到它的工作。我有一个函数PlotAllLayers,它自动将我的data.frame中的所有内容添加到图中。现在我想添加'Dark2'调色板,但它似乎不起作用。ggplot:阴谋中没有颜色
library(ggplot2)
x <- c(0:100)
df <- sapply(seq(5,100,by=10), function(n) dbinom(x,n,.6))
df <- data.frame(x,df)
plotAllLayers<-function(df){
p<-ggplot(data=df,aes(df[,1]))
for(i in names(df)[-1]){
p<-p+geom_line(aes_string(y=i))
}
return(p)
}
testplot <- plotAllLayers(df)
testplot <- testplot + scale_color_brewer(palette="Dark2")
print(testplot)
请不要在脚本的顶部包含'rm(list = ls(all = TRUE))'''。有时,我们会将重要的数据加载到我们的会话中,并且很容易无故地复制您的脚本并清除所有数据。 – nograpes