Skip to content

Make sure jitter is only calculated once #4403

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

Merged
merged 4 commits into from
Apr 9, 2021
Merged

Conversation

thomasp85
Copy link
Member

Fix #2941

This PR changes the jitter position implementation to calculate a jitter once for x and y and then apply that to all position aesthetics

@thomasp85 thomasp85 added this to the ggplot2 3.3.4 milestone Apr 8, 2021
@thomasp85 thomasp85 requested a review from clauswilke April 8, 2021 10:20
@clauswilke
Copy link
Member

I'm not entirely sure yet this works in all edge cases. I believe jitter() will look at the data to consider how much jitter to apply. This gets overwritten with the amount argument, but if amount is NULL or 0 then jitter() again looks at the data. At a minimum this requires a warning in the release notes, I believe.

A safer approach might be to use some actual x or y data columns as dummy data, if available, and then subtract them from the dummy data before applying the jitter. Get's very circuitous, though.

@clauswilke
Copy link
Member

Looks like a long time ago I came up with a different way to solve this issue. See if you like this approach:
https://github.com/clauswilke/ggplot2/blob/ed9be70c14e67e5448ac9f11aadce2cfb868764d/R/position-jitter.r#L75-L91

@thomasp85
Copy link
Member Author

Yeah, I saw that. I still prefer to calculate one jitter value per dimension and apply that. You are right that we need to extract real values for it but that is trivial

Copy link
Member

@clauswilke clauswilke left a comment

Choose a reason for hiding this comment

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

Looks good, but I would flip the order in the intersect() command to get x if available.

intersect(c("xmin", "x", "y"), c("x", "xmin"))[1]
#> [1] "xmin"
intersect(c("x", "xmin"), c("xmin", "x", "y"))[1]
#> [1] "x"

Created on 2021-04-09 by the reprex package (v1.0.0)

@thomasp85
Copy link
Member Author

Ah - good catch... I thought I was doing the right way🙈

@thomasp85 thomasp85 merged commit 15d38fb into master Apr 9, 2021
@thomasp85 thomasp85 deleted the issue2941-jitter branch April 9, 2021 06:59
teunbrand added a commit to teunbrand/ggplot2 that referenced this pull request Apr 2, 2024
teunbrand added a commit that referenced this pull request May 20, 2024
* Follow #4403

* add test

* add news bullet
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.

Vertical line and crossbar jitter being applied differently.
2 participants