我正在尝试将一条简单的最佳拟合线绘制成散点图。
此示例有效:
plot(dist ~ speed, data= cars, xlab="Speed", ylab="Distance", col= "blue")
title(main="Scatter plot with best-fit line", font.main= 4)
abline(lm(dist ~ speed, data= cars), col= "red")然而,对于我的数据,我得到了一条错误消息:
plot(log(datatest$MEAN_intact_for),log(datatest$ERmammal_0_1), col= "blue")
title(main="Scatter plot with best-fit line", font.main= 4)
abline(lm(log(datatest$ERmammal_0_1)~log(datatest$MEAN_intact_for)), col= "red")
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
NA/NaN/Inf in 'x'我已经尝试过搜索它,但我对R是新手,所以如果有人能给我任何简单的建议,那就太好了。
当我只是绘制图形时,它工作得很好,问题是当我添加命令来获得一条最佳拟合线时。我也试过
希望有人能帮上忙。如果真的很明显的话,很抱歉。
发布于 2013-08-01 04:38:29
当您使用abline()时,您需要输入intercept (a)和slope (b)作为参数,而不仅仅是将lm()插入其中。因此,让我们说:
fmla = lm(log(datatest$ERmammal_0_1)~log(datatest$MEAN_intact_for))然后,您需要:
abline(a = fmla$coefficients[1], b = fmla$coefficients[2])https://stackoverflow.com/questions/15179666
复制相似问题