Okay, here you are. I hope that helps. Sorry for the ugly code, I'm using R not often enough to remember all the details ;/
Given this data:
library(ggplot2)
f <- function(x) { return (1-exp(-x/5)); }
data <- data.frame( x = seq(0, 20) )
data$y <- sapply(data$x, f) + rnorm(length(data$x), sd=0.1)
data
ggplot( data,
aes( x= x,
y= y)) +
theme_minimal()+
geom_point()
I can easily plot normalized to f(x) via
ggplot( data, aes( x= x, y= y - f(x))) +
theme_minimal()+
geom_point()
and now only quite a few details are missing, that I could try to fix up like this:
gridlines0 <- data.frame( x= 0:20, y=0-f(0:20))
gridlines1 <- data.frame( x= 0:20, y=1-f(0:20))
gridlines2 <- data.frame( x= 0:20, y=2-f(0:20))
gridlines05 <- data.frame( x= 0:20, y=0.5-f(0:20))
gridlines05
ggplot( data, aes(x= x, y= y-f(x))) +
scale_y_continuous(breaks = NULL)+
theme_minimal()+
geom_line(data=gridlines0) +
geom_line(data=gridlines1) +
geom_line(data=gridlines2) +
geom_line(data=gridlines05) +
geom_text(data=gridlines0[1,], aes(label="0"), nudge_x=-1) +
geom_text(data=gridlines1[1,], aes(label="1"), nudge_x=-1) +
geom_text(data=gridlines2[1,], aes(label="2"), nudge_x=-1) +
geom_text(data=gridlines05[1,], aes(label="0.5"), nudge_x=-1) +
geom_point()
So, basically I'm transforming the coordinate system, with one axis depending on the location on the other axis (here Y depends on X). Now I'd like a) all the grid, grid labels, etc. to be correct without all that (now manual) stuff, and it would be more ideal if I could give a function of two arguments that returns two arguments (instead of now having cood_trans doing two functions of one argument each).