abline 不在 R 中绘图

用户3205880

代码:

plot(medalswimmers$Height, medalswimmers$Weight , cex=1.3, pch=16, xlab="Height of medal winning swimmers (in years)", ylab="Respective weight of medal winning swimmers (in cm)")
lm(medalswimmers$Height ~ medalswimmers$Weight)

输出:

Call:
lm(formula = medalswimmers$Height ~ medalswimmers$Weight)

系数:

(Intercept)  medalswimmers$Weight  
    129.2058                0.7146  

代码:

  abline(a = 129.2058, b= 0.7146, col="Blue") #-THIS DOES NOT PLOT???

没有回归线的绘图图像

斯科特·里奇

您尝试绘制的线在绘图窗口之外。您可以通过计算图极限处 x 值的 y 值来看到这一点:

# What value on the y-axis does the line have when x = 160?
> 129.2058 + 0.7146 * 160
[1] 243.5418

# What value on the y-axis does the line have when x = 200?
> 129.2058 + 0.7146 * 200
[1] 272.1258

这样做的原因是您在与您在线性模型中输入的内容相反的轴上绘制高度和重量。

试试吧:

 l1 <- lm(Height ~ Weight, data=medalswimmers)

 plot(medalswimmers$Weight, medalswimmers$Height, cex=1.3, pch=16, 
      ylab="Height of medal winning swimmers (in years)", 
      xlab="Respective weight of medal winning swimmers (in cm)")

 abline(a=coef(l1)["(Intercept)"], b=coef(l1)["Weight"], color="blue")

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章