Skip to content

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

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit 49b45c1 into tidyverse:main May 20, 2024
@teunbrand teunbrand deleted the jitterdodge_once branch May 20, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error bar line ends are not centered and have variable width when using geom_errorbar with position_jitterdodge

2 participants