我想知道如何在 ggplot 上加上回归线方程和R^2。代码如下:
library(ggplot2)
df <- data.frame(x = c(1:100))
df$y <- 2 + 3 * df$x + rnorm(100, sd = 40)
p <- ggplot(data = df, aes(x = x, y = y)) +
geom_smooth(method = "lm", se=FALSE, color="black", formula = y ~ x) +
geom_point()
p
任何帮助我都感激不尽。
转载于:https://stackoverflow.com/questions/7549694/adding-regression-line-equation-and-r2-on-graph