Sorcha
Sorcha

Reputation: 21

Remove grey background without removing gridlines

Is there a way to remove the grey background from a ggplot graph, without removing the gridlines and without using theme_bw()?

Upvotes: 2

Views: 4091

Answers (1)

stefan
stefan

Reputation: 125418

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

Upvotes: 5

Related Questions