0

I am trying to make a basic scatterplot that displays the regression equation and r2 values in the top left of the plot panel. Below is the code to generate an initial figure with just the r2 value.

plot(OverlapInner$PR1Max, OverlapInner$PR4Max, ylim = c(23, 29), xlim = c(23, 29))
abline(a = 0, b = 1)
fit <- lm(PR1Max ~ PR4Max, data = OverlapInner)
legend("topleft", bty = "n", legend = paste("R2:",format(summary(fit)$adj.r.squared, 
digits=4)))
  • The `abline` function recognizes `lm` objects and can add them for you, try `abline(fit)` – MichaelChirico Apr 01 '20 at 18:06
  • Excellent, but how do paste the equation as text on the figure? –  Apr 01 '20 at 18:08
  • 1
    I marked as duplicate because there are a few questions around getting at what you're after... hopefully the wisdom of the ancients can help. if after searching around for a bit, you're still stuck, please open a new question and there you'll be able to be more specific about what remaining issues you have :) – MichaelChirico Apr 01 '20 at 18:10
  • 2
    I agree this is duplicate but the suggested question doesn't provide the answer. The answer can be found here: https://stackoverflow.com/questions/24173468/r-print-equation-of-linear-regression-on-the-plot-itself – Claudiu Papasteri Apr 01 '20 at 18:13

0 Answers0