1

I need to add regression equation and R2 in this plot. please help me.

x=c(18,23,25,35,65,54,34,56,72,19,23,42,18,39,37)
y=c(202,186,187,180,156,169,174,172,153,199,193,174,198,183,178)
a<-data.frame(cbind(x,y))
library(ggplot2)
ggplot(a,aes(x,y)) +
  geom_point(shape=1,size=3) +
  geom_smooth(method="lm",se=F,color="red")
alireza
  • 113
  • 6
  • 1
    Not sure if `ggpubr` has such a feature but do you just want to add text? `geom_text` perhaps? Also it's difficult to extract these features from `lm` constructed by `ggplot2` except if you manually make the models. – NelsonGon Oct 11 '19 at 06:24
  • 1
    Seems `ggpubr` can do it: https://github.com/kassambara/ggpubr/issues/32 – NelsonGon Oct 11 '19 at 06:34
  • If it might be of some use, I found that a rectangular hyperbola equation "y = a * x / (b + x) + c * x" gave a good fit to the data with parameters a = 1.8730988560720755E+02, b = -1.7858867336591995E+00, and c = -5.0391154158006479E-01 yielding RMSE = 3.731 and R-squared = 0.9303 – James Phillips Oct 11 '19 at 11:53

0 Answers0