拟合线性回归线

时间:2015-03-04 11:38:35

标签: r ggplot2

这听起来像是一个愚蠢的问题,但我在这里看不到我的错误......

set.seed(1234)
df <- data.frame(x=seq(1,100) + rnorm(100),
                 y=seq(1,100) + rnorm(100,10,5))
reg_coeff <- lm(df$x ~ df$y)$coefficients
my_env <- environment()
ggplot(df, aes(x, y)) + 
  geom_point() +
  geom_abline(intercept=reg_coeff[[1]],
              slope=reg_coeff[[2]])

为什么线的拟合不正确?离点数几英里远......

我很困惑......提前致谢!

0 个答案:

没有答案
相关问题