Geom_smooth:添加组时,迭代次数超过50?

时间:2017-06-21 14:00:15

标签: r plot ggplot2 nls

我在建模方面很陌生。我有三组数据(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)

结果:

enter image description here

代码提供错误(在group = period中添加aes),而不是每组显示行:

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中的迭代次数? 我找到了一些信息来增加control=nls.control(maxiter=200) https://stat.ethz.ch/pipermail/r-help/2006-June/107606.html相对于R基础建模的迭代次数,但我无法找到ggplot2的解决方案或方向。

1 个答案:

答案 0 :(得分:0)

基于@Axeman评论,我将java.lang.IllegalStateException: This feature is only available to backend instances. 添加到了

control=nls.control(maxiter=200)

因此整个脚本是:

method.args = list(start=c(a=20, b=0.01), 
                                 control=nls.control(maxiter=200))

结果是:enter image description here