I want to use ggplot to fit an nls function to some data. The nls function is working well when used outside of geom_smooth() but inside it fails.
Code:
library(ggplot2)
df <- structure(list(concentration = c(0, 0.5, 1.5, 4, 12, 35, 100),
response = c(0.015, 0.03673, 0.07212, 0.1027, 0.1286, 0.1858, 0.1812)),
class = "data.frame", row.names = c(NA, -7L))
df.fit <- nls(response ~ k0 + (ki*concentration/(KI + concentration)), df, start = list(k0 = 0.001, ki = 0.18, KI = 1))
coef(df.fit)
plot <- ggplot(df, aes(concentration, response))+
geom_point()+
geom_smooth(method = "nls", se = F, method.args = list(formula = response ~ k0 + (ki*concentration/(KI + concentration)),
start = list(k0 = 0.001, ki = 0.18, KI = 1)))
plot
What am I missing?