0

I am trying to add R^2 values to each facet in a ggplot2 graph. This is the code I have so far and this is what the graph looks like currently.

ggplot(BB_new, aes(x=Date, y=pH, color=Treatment)) + 
  geom_point(pch=19, size=1,alpha = 1)+ 
  geom_smooth(aes(color=NULL), method = "lm", formula = y ~ x + I(x^2), se = FALSE) +
  theme_classic()+ theme(legend.title = element_blank())+
  theme(legend.position = c(0.9,0.93))+
  scale_color_manual(labels = c("Reference"),
  values = c("coral1"))+
  facet_wrap(~Hor) + ylim(2.5, 6) 

enter image description here

Pedro J. Aphalo
  • 5,796
  • 1
  • 22
  • 23
  • Good question! Meanwhile I wait for the question to be re-openned, the short answer is: use `stat_correlation()` or `stat_poly_eq()` from package 'ggpmisc'. – Pedro J. Aphalo Aug 15 '22 at 08:41
  • @PedroJ.Aphalo it's either a dupe of the current one (just calculate r^2 externally and then add it as text) or a dupe of this one https://stackoverflow.com/questions/60143052/how-to-add-r2-for-each-facet-of-ggplot-in-r – user438383 Aug 15 '22 at 08:42
  • 2
    o.k., yes, it is a dupe of the second one. You are correct, I'll add an alternative answer there. – Pedro J. Aphalo Aug 15 '22 at 08:46

0 Answers0