abline不尊重R中的拦截

时间:2015-03-31 14:14:04

标签: r plot

以下代码显示了abline的奇怪行为:绘制的线条未达到指定的截距。我使用Rstudio版本0.98.976。有什么提示可以避免这个问题吗?

x=seq(1,10)
y=seq(1,10)
m=lm(y~x)
summary(m)
plot(x,y)
abline(1.123e-15, 1.000e+00)
abline(2, 1.000e+00)
abline(3, 1.000e+00)
abline(4, 1.000e+00)

提前致谢,

enter image description here

1 个答案:

答案 0 :(得分:3)

这只是一个透视问题,因为截距只是y的值x=0

x=seq(1,10)
y=seq(1,10)
m=lm(y~x)
summary(m)
plot(x,y, ylim = c(0,10), xlim= c(0,10))
abline(1.123e-15, 1)
abline(2, 1.00)
abline(3, 1.00)
abline(4, 1.00)
abline(v=0)

enter image description here