abline() 函数未在图中显示一条线
abline() function not showing a line in plot
正在尝试绘制一条最佳拟合线以及我在 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)
抱歉格式不好...我在移动设备上发帖
您 fit
的等式与您的情节陈述不符。 lm(new)
假设 "species" 是自变量,而 plot(new)
假设 "area" 是。
试试这个:
fit<-lm(species ~ area, data = new)
#Call:
#lm(formula = species ~ area, data = new)
#Coefficients:
#(Intercept) area
# 1.0223 0.2002
正在尝试绘制一条最佳拟合线以及我在 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)
抱歉格式不好...我在移动设备上发帖
您 fit
的等式与您的情节陈述不符。 lm(new)
假设 "species" 是自变量,而 plot(new)
假设 "area" 是。
试试这个:
fit<-lm(species ~ area, data = new)
#Call:
#lm(formula = species ~ area, data = new)
#Coefficients:
#(Intercept) area
# 1.0223 0.2002