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

一个人想着一个人 提交于 2019-12-04 02:33:29

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/26538777/add-regression-line-and-goodness-of-fit-stats-to-scatterplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!