I want to add minor axis ticks and/or lines on a figure generated with ggplot()
. This is a seemingly simple task but has proven very challenging. I found this solution but it is relatively inelegant and does not suit my application. I will be re-making my plot many times with different data, thus changing the axis limits and breaking any manual specifications via geom_vline()
.
I read the documentation for scales::minor_breaks_width()
and tried to use it for the minor_breaks
argument to scale_x_continuous()
but it throws an error about "looping over the breaks".
A reprex is below, can anyone offer a suggestion?
library(tidyverse)
p <- mpg %>%
ggplot(aes(displ, hwy))+
geom_point()
# major breaks are easy to set
p +
scale_x_continuous(
breaks = scales::breaks_width(width = 0.5, offset = 0))
# adding a minor breaks specification throws an error
p +
scale_x_continuous(
breaks = scales::breaks_width(width = 0.5, offset = 0),
minor_breaks = scales::minor_breaks_width(width = 0.01, offset = 0) )
#> Error in loop_breaks(range, breaks, f): argument "breaks" is missing, with no default
Created on 2020-11-19 by the reprex package (v0.3.0)