Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply jitter in position_jitterdodge() once #5819

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

teunbrand
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant