How do I change the background color of a plot made with ggplot2

To change the panel’s background color, use the following code:

myplot + theme(panel.background = element_rect(fill="green", colour="red"))

To change the color of the plot (but not the color of the panel), you can do:

myplot + theme(plot.background = element_rect(fill="green", colour="red"))

See here for more theme details Quick reference sheet for legends, axes and themes.

Leave a Comment