[英]R and ggplot non-linear regression line
I'm trying to fit multiple non-linear regression lines and measured points into a plot and started like this:我正在尝试将多个非线性回归线和测量点拟合到 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)))
The formula in the code is the equation for a langmuir sorption isotherm and all the variables are given in the data=Sorption
.代码中的公式是 langmuir 吸附等温线的方程,所有变量都在data=Sorption
中给出。
When I run this code, I get the following error:当我运行此代码时,我收到以下错误:
**fitting parameters ‘K’, ‘Smax’, ‘Ct’, ‘S’ without any variables
Warning message:
Computation failed in `stat_smooth()`:
object 'S' not found**
I have no idea what I'm doing right or wrong, so if anybody has a lead, I'd be forever grateful;) I'm also not sure about the starting points and what to put in this last line of code.我不知道我在做什么是对还是错,所以如果有人有领导,我将永远感激不尽;)我也不确定起点和最后一行代码的内容。 When I'm running this code I do get the actual measured points in the plot but no non-linear regression line.当我运行这段代码时,我确实得到了 plot 中的实际测量点,但没有非线性回归线。
You can adjust the way you express formula, by using x
and y
directly您可以通过直接使用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)))
An example is with mtcars
一个例子是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.