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

scale_*_continuous fails to render breaks if axis is reversed #5918

Open
tombishop1 opened this issue May 30, 2024 · 4 comments · May be fixed by #5921
Open

scale_*_continuous fails to render breaks if axis is reversed #5918

tombishop1 opened this issue May 30, 2024 · 4 comments · May be fixed by #5921

Comments

@tombishop1
Copy link

Where a scale is reversed in scale_*_continuous, it fails to render any breaks.

For example, the following does not work:
ggplot() + scale_x_continuous(limits = c(10,1))

But the following does work:
ggplot() + scale_x_continuous(limits = c(1,10))

The bug developed somewhere between version 3.4.3 and 3.5.1.

@martinherrerias
Copy link

These seem to work:

ggplot() + scale_x_reverse(limits = c(10,1))
ggplot() + scale_x_continuous(limits = c(10,1), transform = scales::transform_reverse())

These (also) don't:

ggplot() + scale_x_reverse(limits = c(1,10))
ggplot() + scale_x_continuous(limits = c(1,10), transform = scales::transform_reverse())

@teunbrand
Copy link
Collaborator

Strange, I don't think I've encountered this before.
Is flipping the limits supposed to give a reversed scale?
I'm having trouble tracing where this is documented.

@tombishop1
Copy link
Author

Hmm, its a method that has been passed around, although now you mention it I actually don't know whether it is officially supported. The method described in Chang's "The R Graphics Cookbook", when one needs to both reverse an axis and set it's range is as follows:

ggplot() + scale_x_reverse(limits = c(10,1))

This does work.

@teunbrand
Copy link
Collaborator

It sort of makes sense that this works for scale_x_reverse() somehow, as limits get transformed straight away in the scale, so that'd yield effectively limits = c(-10, -1) in transformed space. Invoking transform = "reverse" by having inverse limits sounds tricky to me.

I think that probably the most consistent thing to do is always have sorted limits internally, so that it shouldn't matter if you put limits = c(10, 1) or limits = c(1, 10). That'd also sort out the axis breaks not showing up.

@teunbrand teunbrand linked a pull request May 31, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants