[英]ggplot R grey scale but still colours
我想創建一個置信區間均為灰色的線+點圖,但是我得到了一個彩色圖。
我使用了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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.