'Removing grey background without removing gridlines in ggplot
Is there a way to remove the grey background from a ggplot graph, without removing the gridlines and without using theme_bw()?
Solution 1:[1]
As the default ggplot theme (theme_grey) has a "white" color for the grid lines you have to set a different color for the grid lines when removing the grey background, i.e. when setting the fill for the background to "white" or NA. In the code below I simply use black grid lines:
library(ggplot2)
ggplot(mtcars, aes(hp, mpg)) +
geom_point() +
theme(panel.background = element_rect(fill = "white"),
panel.grid = element_line(color = "black"))

Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | stefan |
