问题
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