ggplot2
ggplot2 copied to clipboard
Apply jitter in `position_jitterdodge()` once
This PR aims to fix #5818.
Briefly, when a geom uses >1 position aesethetic, e.g. xmin
and xmax
instead of just x
, jitters were applied independently to each of the position aesthetics. This PR applies the same remedy as in #4403 applied to position_jitter()
for position_jitterdodge()
.
Reprex from issue, notice that the vertical parts are now centered relative to the hinges:
devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
data = tibble(
x = factor(c('a', 'a', 'a', 'a', 'b', 'b', 'b', 'b')),
group = factor(c('c', 'd', 'c', 'd', 'c', 'd', 'c', 'd')),
lower = seq(0, 3, length.out = 8),
middle = seq(1, 4, length.out = 8),
upper = seq(2, 5, length.out = 8)
)
ggplot(data, aes(x = x, y = middle, color = group)) +
geom_errorbar(
aes(ymin = lower, ymax = upper),
position = position_jitterdodge(dodge.width = 0.75, seed = 1)
)
Created on 2024-04-02 with reprex v2.1.0