Abline未在R中绘制

  • 本文关键字:绘制 未在 Abline r
  • 更新时间 :
  • 英文 :


代码:

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")

最新更新