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

Compute jitter width by panel #6330

Merged
merged 4 commits into from
Mar 25, 2025
Merged

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #3722.

It ensures that the default, resolution-based jitter width is computed per panel instead of per layer.

Reprex from the issue, notice that the jitter has about equal visual spread across panels:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

set.seed(123)
df <- data.frame(
  y = rnorm(100, 50, 10),
  x = c(rep(1:5, 10), rep(seq(0, 100, length.out = 5), 10)),
  group = c(rep("a", times = 50), rep("b", times = 50))
)

ggplot(df, aes(x = x, y = y)) +
  geom_point(color = "orange", alpha = 0.7) +
  geom_point(position = "jitter", color = "blue", alpha = 0.7) +
  facet_wrap( ~ group, scales = "free")

Created on 2025-02-12 with reprex v2.1.1

An open question is whether we should do this for position_jitterdodge() too.

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 7e67db3 into tidyverse:main Mar 25, 2025
13 checks passed
@teunbrand teunbrand deleted the jitter_panels branch March 25, 2025 13:00
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.

Misleading noise when using geom_jitter in combination with facet_wrap
2 participants