Reputation: 93
I know that it's generally looked down upon to have two y-axes for several reasons, but there is a very specific reason for having it here as the two are basically the same concepts and need to be plotted side by side.
Anyway, what I'm hoping to do here is have something similar to
scale_y_reverse(breaks=seq(0,1,.05),
sec.axis = sec_axis(~ 1-., name = "SecondAxis", breaks=seq(0,1,.05) ))
Unfortunately, this doesn't seem to work. I need the primary axis to go from 1 to zero as it goes up, and the second y axis to go from 0 to 1 as it goes up.
Doesn't seem to work unfortunately from the code I have above as you can see above, which was proposed as a solution in another thread.
Upvotes: 2
Views: 302
Reputation: 50678
I can't reproduce your issue.
Update: This seems to be an issue (bug) specific to ggplot2_3.1.0
. There exist a couple of issues on GitHub related to unexpected behaviour of sec_axis
in 3.1.0: sec_axis formula behaviour #2974, Ticks misaligned for sec_axis with some scale transformations and data in 3.1.0 #2978.
The following example is reproducible in ggplot2_3.0.0
but fails in ggplot2_3.1.0
.
Here is a minimal & reproducible example, could you please double-check that this works for you.
# Generate sample data
x <- seq(1, 4 * pi, length.out = 100)
y <- sin(x)^2
library(ggplot2)
ggplot(data.frame(x, y), aes(x, y)) +
geom_point() +
scale_y_reverse(
breaks = seq(0, 1, 0.1),
sec.axis = sec_axis(~ 1 - ., name = "SecondAxis", breaks = seq(0, 1, 0.1)))
Upvotes: 1