Add regression line (and goodness-of-fit stats) to

2020-03-31 04:56发布

After reviewing other stackoverflow posts, I am attempting to add a regression line to my scatter plot with:

plot(subdata2$PeakToGone, subdata2$NO3_AVG, xlim = c(0, 70))
abline(lm(PeakToGone~NO3_AVG, data = subdata2))

However, it is not showing the line. I would also like to add the R^2, RMSE, and p-value from lm as text on the plot.

How can I add the regression line to the plot, along with these goodness-of-fit stats?

标签: r plot line lm
1条回答
Rolldiameter
2楼-- · 2020-03-31 05:48

By default, plot regards the 1st param as x and the 2nd as y. Try

plot(y = subdata2$PeakToGone, x = subdata2$NO3_AVG, xlim = c(0, 70))
abline(lm(PeakToGone~NO3_AVG, data = subdata2))

and look if the line is visible, now. You'll find an answer to your 2nd question here.

查看更多
登录 后发表回答