简体   繁体   English

R没有绘制回归线

[英]R not drawing regression line

So I'm trying to get a regression line to show up on the data plot, and it isn't working. 所以我试图得到一条回归线来显示数据图,但它不起作用。 I tried restarting R, checked the code, it looks totally fine to me. 我尝试重新启动R,检查代码,它看起来对我来说完全没问题。 The abline() command worked for every other plot I've made today, just not this one. abline()命令适用于我今天制作的每一个情节,而不是这个。

Here's the commands I used: 这是我使用的命令:

hw3c <- read.csv(file.choose(), header = T)
model.3c <- lm(hw3c)
plot(hw3c)
abline(model.3c)

The data is: 数据是:

Crab,Sal
0.7,3
1.7,3.2
1.3,6.5
2.2,6.5
0.9,9.4
3.2,23.4
5,27.1

I know this is stupidly simple, I don't get why it isn't working. 我知道这很简单,我不明白为什么它不起作用。 Help? 救命?

Your model is Crab ~ Sal while your plot is Sal ~ Crab . 你的模型是Crab ~ Sal而你的情节是Sal ~ Crab Change one or the other. 改变一个或另一个。 Eg: 例如:

abline(lm(Sal ~ Crab, data=hw3c))

gives you a line of best fit. 为您提供最佳选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM