abline()函数未在图中显示一条线

时间:2019-01-24 00:03:14

标签: r lm

尝试绘制一条最适合的线条以及我在R中的数据集。数据是从.csv文件导入的。

除abline()函数外,其他所有东西似乎都能正常工作。

Data=read.csv("R/SpecArea.csv")
Data

new=log10(Data)
new

fit=lm(new)

fit

plot(new)
abline(fit)

感谢您的帮助。

这是整个程序的输出:

Data=read.csv("R/SpecArea.csv")
Data
    area species
1  44164      79
2  29979      79
3   4411      68
4   3423      54
5    583      34
6    385      41
7    305      40
8    233      44
9    160      16
10   133      38
11   120      22
12   108      23
13    80      29
14    71      29
15    68      21
16    62      22
17    38      24
18    33      17
19    32      24
> 
> new=log10(Data)
> 
> new
       area  species
1  4.645068 1.897627
2  4.476817 1.897627
3  3.644537 1.832509
4  3.534407 1.732394
5  2.765669 1.531479
6  2.585461 1.612784
7  2.484300 1.602060
8  2.367356 1.643453
9  2.204120 1.204120
10 2.123852 1.579784
11 2.079181 1.342423
12 2.033424 1.361728
13 1.903090 1.462398
14 1.851258 1.462398
15 1.832509 1.322219
16 1.792392 1.342423
17 1.579784 1.380211
18 1.518514 1.230449
19 1.505150 1.380211
> 
> fit=lm(new)
> 
> fit

Call:
lm(formula = new)

Coefficients:
(Intercept)      species  
     -3.508        3.941  


 plot(new)
 abline(fit)

很抱歉格式不正确...我正在移动设备上发布

1 个答案:

答案 0 :(得分:1)

您的fit方程式与您的绘图语句不匹配。 lm(new)假设“物种”是自变量,而plot(new)假设“区域”是自变量。

尝试使用此:

fit<-lm(species ~ area, data = new)

#Call:
#lm(formula = species ~ area, data = new)

#Coefficients:
#(Intercept)         area  
#     1.0223       0.2002  

enter image description here