【发布时间】:2020-11-10 15:23:08
【问题描述】:
我想知道如何用指数回归模型拟合这些数据,以及如何在 ggplot 图上打印指数回归方程和 R2。使用 geom_smooth() 来拟合数据会更好。我找到了几种可能的解决方案,但仅适用于线性回归,而我对指数型回归很感兴趣。这是我的代码:
library(ggplot2)
##### Creating the data frame
x <- c(0.54,0.59,0.57,0.54,0.10,0.07,0.17,0.24,0.51,0.57,0.55,0.52,0.40,0.43,0.45,0.43)
y <- c(156.9,234.8,191.9,203.2,59.8,36.0,87.2,23.8,168.7,182.3,155.8,205.1,101.2,115.5,118.8,159.1)
df <- data.frame(x, y)
##### Creating the plot
my_plot <- ggplot(data = df, mapping = aes(x, y)) +
geom_point()
my_plot
这是结果图:
任何帮助将不胜感激。
【问题讨论】:
-
我在您的代码中没有看到“指数回归”。我看到一个简单的二次回归(是线性回归,毕竟你使用的是
lm)。
标签: r ggplot2 regression