[英]R and ggplot non-linear regression line
我正在尝试将多个非线性回归线和测量点拟合到 plot 中,并像这样开始:
ggplot(Sorption, aes(x=Ct, y=S, color=Depth)+
geom_point()+
geom_smooth(method = "nls", data = Sorption,
se = FALSE,
formula = 'S~Smax*K*Ct/1+K*Ct',
method.args = list(start=c(K=2, Smax=1100, Ct=0.2, S=0.2)))
代码中的公式是 langmuir 吸附等温线的方程,所有变量都在data=Sorption
中给出。
当我运行此代码时,我收到以下错误:
**fitting parameters ‘K’, ‘Smax’, ‘Ct’, ‘S’ without any variables
Warning message:
Computation failed in `stat_smooth()`:
object 'S' not found**
我不知道我在做什么是对还是错,所以如果有人有领导,我将永远感激不尽;)我也不确定起点和最后一行代码的内容。 当我运行这段代码时,我确实得到了 plot 中的实际测量点,但没有非线性回归线。
您可以通过直接使用x
和y
来调整表达公式的方式
ggplot(Sorption, aes(x=Ct, y=S, color=Depth, group=Depth))+
geom_point()+
geom_smooth(method = "nls", se = FALSE,
formula = y~Smax*K*x/1+K*x,
method.args = list(start=c(K=2, Smax=1100)))
一个例子是mtcars
ggplot(mtcars, aes(x=disp,y=mpg, color=as.factor(cyl), group=as.factor(cyl)))+
geom_point() +
geom_smooth(
method = "nls", se = FALSE,
formula = y~A*x^2 + B*x + C,
method.args=list(start=c(A=1, B=1, C=1))
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.