trying to display original and fitted data (nls + dnorm) with ggplot2's geom_smooth() trying to display original and fitted data (nls + dnorm) with ggplot2's geom_smooth() r r

trying to display original and fitted data (nls + dnorm) with ggplot2's geom_smooth()


the first error indicates that ggplot2 cannot find the variable 'count', which is used in formula, in data.

Stats take place after mapping, that is, size -> x, and counts -> y.

Here is an example for using nls in geom_smooth:

ggplot(data=myhist, aes(x=size, y=counts)) + geom_point() +   geom_smooth(method="nls", formula = y ~ N * dnorm(x, m, s), se=F,               start=list(m=20, s=5, N=300)) 

The point is that using x and y, instead of size and counts, in the specification of formula.