In discrete scales, the breaks are centered on groups, which can sometimes make it difficult to visually discern where groups start and end. To add more visual cues about this, I think it is a good idea to add a minor.breaks argument to discrete position scales, that subsequently puts minor panel grid lines at those positions. I also thinks it may pair well with #5287. Essentially, I'd like to have the following visual:
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.3.1
ggplot(mpg, aes(class, fill = factor(cyl))) +
geom_bar(position = position_dodge(preserve = "single")) +
annotate(
"segment",
x = 1.5:6.5, xend = 1.5:6.5,
y = -Inf, yend = Inf,
colour = 'white'
) +
theme(panel.grid.major = element_blank())

But with this syntax:
ggplot(mpg, aes(class, fill = factor(cyl))) +
geom_bar(position = position_dodge(preserve = "single")) +
scale_x_discrete(minor.breaks = 1.5:6.5) +
theme(panel.grid.major = element_blank())
Created on 2023-09-22 with reprex v2.0.2
In discrete scales, the
breaksare centered on groups, which can sometimes make it difficult to visually discern where groups start and end. To add more visual cues about this, I think it is a good idea to add aminor.breaksargument to discrete position scales, that subsequently puts minor panel grid lines at those positions. I also thinks it may pair well with #5287. Essentially, I'd like to have the following visual:But with this syntax:
Created on 2023-09-22 with reprex v2.0.2