我想用灰色的置信区间创建一个线+点图,但我得到一个彩色图。
我使用了scale_fill_grey选项,但这仅适用于置信区间,而不适用于线和点。
a<-ggplot(df, aes(x = Yr, y = SIR, color=Type, shape=Type,linetype=Type))+geom_point(size=2.5) + geom_smooth(method=lm, aes(fill=Type))
a + scale_fill_grey(start=0.8, end=0.5)+labs(x="Year", y="SIR")+theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))
如何获得BW灰色图?谢谢!
要更改点和线的颜色,您需要使用colour
美学而不是fill
。
使用iris
数据集创建类似的图,并添加scale_fill_grey()
将仅为您的图的置信区域着色:
a<-ggplot(iris, aes(x = Petal.Length, y = Sepal.Length, color=Species, shape=Species,linetype=Species))+geom_point(size=2.5) + geom_smooth(method=lm, aes(fill=Species))
a + scale_fill_grey()
要获得积分,您需要添加scale_color_grey()
:
a + scale_fill_grey() + scale_color_grey()
有关ggplot颜色美学的更多详细信息,请参阅文档:https://ggplot2.tidyverse.org/reference/aes_colour_fill_alpha.html