Open tombishop1 opened 1 month ago
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())
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.
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.
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.
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.