I'm having trouble showing the fitted exponential equation on a plot. I used ggplot2 and stat_smooth()
to draw the points and fitted lines. Now I want to show the fitted equation on the plot but stat_poly_eq()
does not work. Does anyone know how to do that? My code is attached here.
mydata = data.frame("conc_ensemble" = c( 2.000000, 2.477121, 2.778151, 2.954243, 3.000000, 3.477121, 3.778151, 3.954243, 4.000000,
4.477121, 4.778151, 4.954243, 5.000000, 5.477121, 5.778151, 5.954243, 6.000000),
"REV" = c(5.20000, 3.76000, 2.23000, 1.96000, 1.57500, 1.00000, 0.71250, 0.65000, 0.49000, 0.28300, 0.22900, 0.17500,
0.16225, 0.08830, 0.06075, 0.06075, 0.05350))
my.formula = y ~ a*exp(b*x)
ggplot(mydata, aes(conc_ensemble, REV) ) +
geom_point() +
stat_smooth(method = 'nls', method.args = list(start = c(a=1, b=1)),
formula = my.formula, colour = 'red', se = FALSE) +
stat_poly_eq(formula = my.formula,
label.x.npc = 0.2, size = 3,
aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~")),
parse = TRUE,
rr.digits = 3)