【问题标题】:Plot output of non-linear model output in ggplot2在 ggplot2 中绘制非线性模型输出的输出
【发布时间】:2021-05-27 20:43:45
【问题描述】:

我有一些数据,其中最适合的非线性回归是 S 曲线模型。我想在 ggplot2 中绘制 S 曲线,但不知道如何指定这个模型。我假设我应该使用以下代码,但不知道如何指定方法或公式。有人可以帮忙吗?

'''geom_smooth(方法 = XXX, method.args = list(formula = XXX)'''

【问题讨论】:

    标签: r ggplot2 non-linear


    【解决方案1】:

    您可以将预测包装在geom_function() 中。下面带有内置数据集的示例:

    library(ggplot2)
    
    # From the ?nls examples
    df <- subset(DNase, Run == 1)
    fit <- nls(density ~ SSlogis(log(conc), Asym, xmid, scal), df)
    
    ggplot(df, aes(conc, density)) +
      geom_point() +
      geom_function(
        fun = function(x) {
          predict(fit, newdata = data.frame(conc = x))
        },
        colour = "red",
      ) +
      scale_x_continuous(trans = "log10")
    

    【讨论】:

      猜你喜欢
      • 2021-03-01
      • 2018-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多