0

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?

thelatemail
  • 91,185
  • 12
  • 128
  • 188
viridius
  • 477
  • 5
  • 17
  • 3
    In general: It's best practice to provide a [reproducible example](http://adv-r.had.co.nz/Reproducibility.html), ready to copy, paste and run. By default, `plot` regards the 1st param as `x` and the 2nd as `y`. Try `plot(y=subdata2$PeakToGone, x=subdata2$NO3_AVG, ...` and look if the line is visible, now. You'll find an answer to your 2nd question here http://stackoverflow.com/questions/13114539/how-to-add-rmse-slope-intercept-r2-to-r-plot#answer-13119440 – lukeA Oct 23 '14 at 23:17
  • @lukeA - that looks to be the drama, a simple mismatch in plotting or the specification of the `lm` formula. Add that as an answer as it is probably a common problem. – thelatemail Oct 23 '14 at 23:19

1 Answers1

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.

Community
  • 1
  • 1
lukeA
  • 53,097
  • 5
  • 97
  • 100