ArTu
ArTu

Reputation: 483

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

enter image description here

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

Upvotes: 0

Views: 3827

Answers (1)

Andrew Haynes
Andrew Haynes

Reputation: 2640

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

enter image description here

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

a + scale_fill_grey() + scale_color_grey()

enter image description here

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

Upvotes: 2

Related Questions