I would like to have two axis using different scales/units, both matching one single dataset. The problem is that the two axis are non-monotonic. An example is shown below:
library(ggplot2)
d <- data.frame(
time = c(1:10),
signal1 = seq(10, 100, by=10),
signal2 = c(10,11,13,14.2, 14.5, 16, 18, 18.2,19.6, 20)
)
axis.transform <- approxfun(d$signal1, d$signal2)
ggplot(d, aes(x=time, y=signal1)) + geom_point() +
scale_y_continuous(
"signal 1",
sec.axis = sec_axis(~axis.transform(.), name = "signal 2")
)