I have two data.frames, one containing raw data and the other containing modelling coefficients that I have derived from the raw data.
More detail: The first data.frame "raw" contains "Time" (0s to 900s) and "OD" for many Variants and four runs. The second data.frame "coef" contains one row per Variant/run combination, with the individual coefficients ("M", "D.1" and "t0.1") in that row.
I have plotted the raw data split per Variant and coloured by runID, no problem. But now I want to overlay the model curves according to the runID.
Since the modelling coeffients are in a different data.frame (with different dimensions, so I can't just cbind them), stat_function won't work for me. I can get on curve showing at a time.
I have tried with a for(){} loop, adding a stat_function layer each time:
p <- ggplot(temp, aes(Time, OD)) + geom_point(aes(colour = runID), size = 2) #works fine!
calc <- function(x){temp.n$M[ID] * (1 - exp(temp.n$D.1[ID] * temp.n$t0.1[ID] - x)))}
for(ID in 1:length(unique(temp.n$runID))) {
p <- p + stat_function(fun = calc)
}
print(p)
At the end, all "p" returns is the plot of the raw data and the final curve from the looping bit. "p" seems to revert to its original state every time I try to add a new "stat_function" layer.
Any ideas?