-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Hi,
When working with discrete axes, panel.grid.major draws lines exactly on the tick marks.
That’s expected, but it's often visually undesirable, as separators between categories would be more readable.
Right now, ggplot2 offers no native way to do that, as panel.grid.minor has no effect for discrete axes
A known workaround is to manually compute midpoints and then plot them using geom_hline().
It works, but it is not tidy, as it requires a reference to the original data to compute midpoints, breaking the pipeline in the process.
Here is a reprex of the expected output (that could obviously be much improved):
library(tidyverse)
data = tibble(
SUBJID = rep(letters[1:6], each = 2),
dose = c(rep("A", 4), rep("B", 8)),
value = seq(12),
)
p = data %>%
ggplot() +
aes(y=SUBJID, x=value) +
geom_point() +
geom_hline(yintercept = seq(0.5, n_distinct(data$SUBJID), by=1)) +
theme(
legend.position="none",
panel.grid.minor.y = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.x = element_blank(),
axis.ticks.y= element_blank(),
)
p
If you could enable minor_breaks for discrete axes, I think it would improve readability for many plots with discrete rows or columns, without requiring shady boilerplate code.
Thanks for considering it!