我在建模方面很陌生 . 我有三组数据(通过 period
),我想通过散点图上的线条显示 .
我想出了如何将我的方法和公式放在 geom_smooth
中,我能够显示一行 .
但是,当我想为每个组添加行数(可以通过 ggplot(.., aes(..,group = period))
来完成)时,我收到了警告:
Warning message:
Computation failed in `stat_smooth()`:
number of iterations exceeded maximum of 50
并且不显示该行 .
我的工作代码:
ggplot(tab, aes(x=distance, y=grad)) + #
geom_point() + theme_bw() +
geom_smooth(method = "nls",
formula = y ~ a*x^(-b),
method.args = list(start=c(a=20, b=0.01)), #
se = F)
结果:
代码提供错误(在 aes
中添加 group = period
),而不是每组显示行:
ggplot(tab, aes(x=distance, y=grad, group = period)) + #
geom_point() + theme_bw() +
geom_smooth(method = "nls",
formula = y ~ a*x^(-b),
method.args = list(start=c(a=20, b=0.01)), #
se = F)
您是否有一些想法如何通过geom_smooth函数增加ggplot2中的迭代次数?我找到了一些信息来增加相对于R基础建模的 control=nls.control(maxiter=200)
https://stat.ethz.ch/pipermail/r-help/2006-June/107606.html的迭代次数,但我找不到ggplot2的解决方案或方向 .
1 回答
基于@Axeman评论,我将
control=nls.control(maxiter=200)
添加到了因此整个脚本是:
结果是: