简体   繁体   中英

ggplot R grey scale but still colours

I want to create a line+dots plot with confidence intervals all in grey, but I obtain a coloured plot.

I used the option scale_fill_grey but this worked only on the confidence intervals and not on lines and points.

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

在此处输入图片说明

How can I obtain a BW-grey plot? Thank you!

To change the colour of your points and lines, you need to use the colour aesthetic and not fill .

Creating a similar plot with the iris dataset, and adding scale_fill_grey() will only colour the confidence areas of your plot:

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

在此处输入图片说明

To get the points as well, you need to add scale_color_grey() :

a + scale_fill_grey() + scale_color_grey()

在此处输入图片说明

For more details on ggplot colour aesthetics, see the docs: https://ggplot2.tidyverse.org/reference/aes_colour_fill_alpha.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM