
Benjamin B. answered 06/21/19
Ecologist with 4 years of R and research experience
You can change the ggplot background by changing the theme of the plot. You can change the background to a pure white background or a completely black background. You would do this using the same code you have above, but add another part. See example below:
ggplot(data=data.frame(a=c(1,2,3), b=c(2,3,4)), aes(x=a, y=b)) +
geom_line()+
theme_bw()
theme_bw() sets the background to white and uses black and white colors
theme_dark() sets the background to a dark grey/ black
For more information on how to modify the colors specific parts of the graph, please see: http://www.sthda.com/english/wiki/ggplot2-themes-and-background-colors-the-3-elements
You can also change the background to a specific color using the theme() function. The following is example code that would turn your background red
ggplot(data=data.frame(a=c(1,2,3), b=c(2,3,4)), aes(x=a, y=b)) +
geom_line()+
theme(panel.background = element_rect(fill = "red")).