0

I'm new to R.

I have produced the following plot but want to know how to include an R^2 value on the linear model line using ggpmisc and the stat_poly_eq function. The code I have is as follows -

ggplot(xray, aes(x=PercentGoodFish1g, y=PercentPopAff)) +
  geom_smooth(method='lm') +
  geom_point()

Can somebody help with this? I have visited links with examples but can't make sense of the code and what it is doing in order to apply it to my plot.

Thanks

Harry H-W
  • 33
  • 4
  • 2
    See my answer here: https://stackoverflow.com/questions/58835392/annotate-r-squared-to-ggplot-by-using-facet-wrap/58841957#58841957 – Stéphane Laurent Nov 20 '19 at 16:01
  • 1
    @Harry H-W When new to R it is too easy to be unaware that most R functions are well documented. In this case the first example in the help page for stat_poly_eq() shows how to add R^2 to a plot. Checking the documentation is frequently the fastest way to solve a problem like this. – Pedro J. Aphalo Nov 22 '19 at 17:03

0 Answers0