Say I have the following data:
require(ggplot2)
set.seed(123)
data <- data.frame(x = sample(1:20, 100, replace = TRUE))
I want to create a dot plot of data$x, so this is what I do:
ggplot(data, aes(x)) +
geom_dotplot(binwidth = 1) +
scale_x_continuous(breaks = seq(1, 20, 1)) +
scale_y_continuous(breaks = NULL)
Which gives me this:

I would like to get rid of those vertical grid lines, so I add theme(line = element_blank()) to my ggplot statement. The problem is that command also eliminates the tick marks, which I would like to keep. How can I hide the grid lines whilst keeping their respective ticks?
I would also like to know how I can change the grid lines so they'll be drawn every 1:20, not at every 0.5 mark.
I've looked for those answers in ?title() and ?geom_dotplot, tried a couple of things, to no avail. Appreciate the help!
Use panel.grid
theme(panel.grid = element_blank())

If you want the grid lines to be drawn every 1:20, not at every 0.5 mark.
theme(panel.grid.minor = element_blank(),
panel.grid.major = element_line(colour = "white",size=0.75))

you might find answers here
opts has been changed to theme. but the thing about grid.major.x, grid.minor.y should set on the track
To get rid of the major grid line, for example
ggplot(data, aes(x)) +
geom_dotplot(binwidth = 1) +
scale_x_continuous(breaks = seq(1, 20, 1)) +
scale_y_continuous(breaks = NULL) + theme(panel.grid.major = element_blank())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With