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

geom_curve curvature direction is inconsistent on flipped axes #5069

Open
Torvaney opened this issue Nov 30, 2022 · 2 comments · May be fixed by #6332
Open

geom_curve curvature direction is inconsistent on flipped axes #5069

Torvaney opened this issue Nov 30, 2022 · 2 comments · May be fixed by #6332
Labels
bug an unexpected problem or unintended behavior layers 📈

Comments

@Torvaney
Copy link

The direction of the curvature in geom_curve is inconsistent with respect to other plot elements. This is easy to work around, but it would be nice if it were consistent.

See the following examples:

library(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)

p + ggtitle("In the base plot, the curve arcs away from the points...")

p + coord_flip() + 
  ggtitle("Flipped, the curve arcs *towards* from the points...")

p + coord_flip() + scale_y_reverse()+ 
  ggtitle("Flipped reversed, the curve arcs away from the points again!")

Created on 2022-11-30 with reprex v2.0.2

@teunbrand
Copy link
Collaborator

One special property of geom_curve(), or to be more precise grid::curveGrob(), is that the coordinates of the segments along the curve are unknown until it is drawn on the device. That makes it hard to precisely control those coordinates inside ggplot2.

I've played around with this issue a bit, and while it would be possible to change the sign of the curvature parameter when using coord_flip(), that still leaves some inconsistency with regards to reversed scales.

In theory, it should be possible to add a third point that won't be drawn, but that forms a triangle with the start and end of the segments. If that point has changed sides relative to the start and end coordinates during transformation, the curvature could be assigned the opposite sign.

However, that approach would have the downside that the third point would affect scale training, which is not ideal, so we'd be fixing a problem by introducing another one. Unfortunately, I can't really see an elegant solution to this issue.

@Torvaney
Copy link
Author

Thanks @teunbrand - I understand, and appreciate you looking into it.

@teunbrand teunbrand added the bug an unexpected problem or unintended behavior label Dec 23, 2022
@teunbrand teunbrand linked a pull request Feb 14, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior layers 📈
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants