Skip to content

No ticks when the limit of Coord is in the opposite order to the Scale #3952

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

Closed
yutannihilation opened this issue Apr 18, 2020 · 3 comments · Fixed by #3958
Closed

No ticks when the limit of Coord is in the opposite order to the Scale #3952

yutannihilation opened this issue Apr 18, 2020 · 3 comments · Fixed by #3958
Labels
bug an unexpected problem or unintended behavior scales 🐍

Comments

@yutannihilation
Copy link
Member

(Originally reported at #3948)

Should the p1 below be errored? Or, should the ticks be drawn?

library(ggplot2)
library(patchwork)

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

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

p1 <- p + coord_cartesian(ylim = c(1, 10))
p2 <- p + coord_cartesian(ylim = c(10, 1))
p1 / p2

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

@clauswilke
Copy link
Member

I think axis ticks should be drawn. Note that the problem exists even without scale_y_reverse().

library(ggplot2)
library(patchwork)

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

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

p1 <- p + coord_cartesian(ylim = c(1, 10))
p2 <- p + coord_cartesian(ylim = c(10, 1))
p1 / p2

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

@yutannihilation
Copy link
Member Author

Oh, I didn't notice it... Thanks.

@yutannihilation yutannihilation changed the title What is the expected behaviour when the limit of Coord is in the opposite order to the Scale? No ticks when the limit of Coord is in the opposite order to the Scale Apr 19, 2020
@yutannihilation
Copy link
Member Author

yutannihilation commented Apr 22, 2020

Under the hood, this seems a problem of scale. Here, scale$get_breaks(continuous_range) returns NAs if the continuous_range is in the opposite order.

breaks <- scale$get_breaks(continuous_range)

library(ggplot2)

scale <- scale_x_continuous()
scale$train(c(1, 3, 5))
scale$get_breaks(c(1, 5))
#> [1] 1 2 3 4 5
scale$get_breaks(c(5, 1))
#> [1] NA NA NA NA NA

In addition, I have no idea what is the expected behaviour in the case below. Should this be errored...?

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

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

p + scale_y_continuous(limits = c(10, 1))
#> Warning: Removed 4 rows containing missing values (geom_point).

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

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 scales 🐍
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants