1

Basically I would like to remove some of the vertical gridlines in my plot. Note that this is not a duplicate of How can I suppress the vertical gridlines in a ggplot2 plot? since this subjet is about deleting all the vertical gridlines.

Here is a minimal reproductible example :

ggplot(diamonds) +
  aes(x = price) + 
  geom_histogram(
    color = 'white',
    fill = 'blue4'
    ) + 
  theme_minimal() 

I would like to supress the vertical gridline which are not associated to a label (5000, 10000, ...).

I tried :

p +
 theme(
   panel.grid.major.x = element_blank()
   )

but it actually does the opposite of what I'm looking for : It deletes the lines associated to a label, instead of the 'useless' ones.

Ronak Shah
  • 286,338
  • 16
  • 97
  • 143
Haezer
  • 355
  • 1
  • 10

1 Answers1

2

Try using panel.grid.minor.x

library(ggplot2)

ggplot(diamonds) +
  aes(x = price) + 
  geom_histogram(
    color = 'white',
    fill = 'blue4'
  ) + 
  theme_minimal() +
  theme(panel.grid.minor.x = element_blank())
Ronak Shah
  • 286,338
  • 16
  • 97
  • 143