【问题标题】:Receive the equation of the stat_smooth in ggplot2 R mtcars example在 ggplot2 R mtcars 示例中接收 stat_smooth 的方程
【发布时间】:2017-06-20 08:21:42
【问题描述】:

您好,我想知道如何在 ggplot2 或向量或其他地方检索 stat_smooth 的方程。我使用的代码是:

p <- ggplot(data = mtcars, aes(x = disp, y = drat)) 
p <- p + geom_point() + stat_smooth(method="loess") 
p

谢谢

【问题讨论】:

  • 我认为你唯一的选择是直接进入stat_smooth的代码。首先你的目标是什么?
  • 使用方程(最佳拟合)并将其推广到相似的数据拟合

标签: r ggplot2 equation coefficients


【解决方案1】:

ggpmisc 包非常有用。但是,它不适用于黄土,因为黄土没有给出公式。见这里:Loess Fit and Resulting Equation

library(ggplot2)
library(ggpmisc)
p <- ggplot(data = mtcars, aes(x = disp, y = drat)) +
  geom_point() + 
  geom_smooth(method="lm", formula=y~x) +
  stat_poly_eq(parse=T, aes(label = ..eq.label..), formula=y~x)
p

【讨论】:

  • 那么除了黄土函数还有其他替代方法吗?与否
  • loess 是数据趋势的可视化。如果你想要一个方程,我建议你应用回归技术,如线性模型、多项式回归或广义自适应模型 (GAM)。然而,在大多数情况下,您需要先验定义数据之间的关系,例如 y~x 或 y~x+x^2。这是关于您的问题的很好的讨论:link
猜你喜欢
  • 2016-06-26
  • 1970-01-01
  • 2016-01-22
  • 2013-08-12
  • 2017-09-07
  • 2017-10-02
  • 1970-01-01
  • 2019-01-17
  • 1970-01-01
相关资源
最近更新 更多