In an experiment, blood pressure is measured at several time points. Blood pressure rises and declines during the experiment. I need to plot the blood pressure reaction (the
No, this can't be done with ggplot2. However, it's easy to do:
v0 <- 10
f1 <- approxfun(df$time, df$value)
#we use numeric optimization here, but an analytical solution is of course possible (though a bit more work)
#this finds only one intersection, more work is required if there are more than one
optimize(function(t0) abs(f1(t0) - v0), interval = range(df$time))
#$minimum
#[1] 96.87501
#
#$objective
#[1] 3.080161e-06
If your data is bijective it gets even simpler:
f2 <- approxfun(df$value, df$time)
f2(v0)
#[1] 96.875