English 中文(简体)
ggplot2 - Background Colors
  • 时间:2024-12-22

ggplot2 - Background Colors


Previous Page Next Page  

There are ways to change the entire look of your plot with one function as mentioned below. But if you want to simply change the background color of the panel you can, use the following −

Implementing Panel background

We can change the background color using following command which helps in changing the panel (panel.background) −


> ggplot(iris, aes(Sepal.Length, Species))+geom_point(color="firebrick")+
+ theme(panel.background = element_rect(fill =  grey75 ))

The change in color is clearly depicted in picture below −

Implementing Panel Background

Implementing Panel.grid.major

We can change the grid pnes using property “panel.grid.major” as mentioned in command below −


> ggplot(iris, aes(Sepal.Length, Species))+geom_point(color="firebrick")+
+    theme(panel.background = element_rect(fill =  grey75 ),
+    panel.grid.major = element_pne(colour = "orange", size=2),
+    panel.grid.minor = element_pne(colour = "blue"))
Implementing Panel Background

We can even change the plot background especially excluding the panel using “plot.background” property as mentioned below −


ggplot(iris, aes(Sepal.Length, Species))+geom_point(color="firebrick")+
+   theme(plot.background = element_rect(fill =  pink ))
Plot Background Advertisements