Skip to content

Flip geom_curve() direction in some circumstances #6332

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 7 commits into from
Mar 25, 2025

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

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, though the flip_curve logic will be a nightmare to maintain :-)

Can't see any other way except for ignoring the issue though

@teunbrand teunbrand merged commit ffdfc23 into tidyverse:main Mar 25, 2025
12 of 13 checks passed
@teunbrand teunbrand deleted the curve_flipping branch March 25, 2025 13:34
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
2 participants