So Im using nls in ggplot2 to plot a power curve code is below:
mass <- c(4120,4740,5550,5610,6520,6870,7080,8500,8960,10350,10480,10550,11450,11930,12180
Your question is answered in this question on the ggplot2 mailing list. Briefly,
According to the documentation for predict.nls, it is unable to create standard errors for the predictions, so that has to be turned off in the stat_smooth call. .
So, we need to turn off the standard errors:
ggplot(df, aes(x=Mass, y=Solv)) +
stat_smooth(method="nls", formula=y~i*x^z, se=FALSE,
start=list(i=1,z=0.2)) +
geom_point(shape=1)
Update 2019: for new versions of ggplot2, we need the start
argument to nls
to be passed like this:
ggplot(df, aes(x = Mass, y = Solv)) +
stat_smooth(method = "nls",
se = FALSE,
method.args = list(
formula = y ~ i*x^z,
start = list(i=1, z=2)
)) +
geom_point()