Skip to content

Allow specifying the limit of Coord in the opposite order to the Scale #3958

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

Conversation

yutannihilation
Copy link
Member

Fix #3952

ylim and xlim of coord_cartesian() can be specified in arbitrary order. But, ScaleContinuous$get_breaks() always expects the limits are in the same order to their order. If not, it returns NA and we'll see no ticks. So, the limits should be sorted before passing to it.

I think scale should raise more explicit warnings or errors, but it's out of scope of this PR.

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

library(patchwork)

d <- base::data.frame(
  x = 1:4,
  y = 1:4
)

p <- ggplot(d, aes(x, y)) +
  geom_point()

p1 <- p + coord_cartesian(ylim = c(1, 10)) + ggtitle("(usual plot)")
p2 <- p + coord_cartesian(ylim = c(10, 1)) + ggtitle("Coord is reversed")
p3 <- p + scale_y_reverse() + coord_cartesian(ylim = c(1, 10)) + ggtitle("Scale is reversed, but Coord is not")
p4 <- p + scale_y_reverse() + coord_cartesian(ylim = c(10, 1)) + ggtitle("Scale and Coord are reversed")

wrap_plots(p1, p2, p3, p4)

Created on 2020-04-22 by the reprex package (v0.3.0)

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

@yutannihilation yutannihilation merged commit 1d4c573 into tidyverse:master May 3, 2020
@yutannihilation yutannihilation deleted the fix/issue-3952-allow-reverse-coord branch May 3, 2020 04:19
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.

No ticks when the limit of Coord is in the opposite order to the Scale
2 participants