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

Flip geom_curve() direction in some circumstances #6332

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

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5069.

Briefly, when reversing or flipping scales, we need to adjust the curves in geom_curve() to be consistent. This PR flips curves by swapping the start- and end coordinates.

The approach harcodes some conditions wherein the swap needs to happen as there isn't a sensible way to derive that from the data itself. The downside of this is that a user can implement a reversing transformation with a different name and we wouldn't detect this.

Also geom_curve() wasn't covered by any tests, so I added some visual ones.

Based on the reprexe in the linked issue; note that the curve consistently curves 'outward' (away from the panel centre).
The missing panel grid is due to #6293.

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

p <- 
  ggplot(mtcars, aes(x = drat, y = mpg)) +
  geom_point() +
  annotate("curve", x = 4.5, xend = 4.5, y = 20, yend = 15, curvature = -1, arrow = arrow())

p

p + coord_flip()

p + coord_flip() + scale_y_reverse()

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

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.

geom_curve curvature direction is inconsistent on flipped axes
1 participant