I have a data.frame (which I melted using the melt function), from which I produce multiple scatter plots and fit a regression line using the following:
ggplot(dat, aes(id, value)) + geom_point() + geom_smooth(method="lm", se=FALSE) + facet_wrap(variable~var1, scales="free")
I would like to add the regression equation and the R^2 in each of these scatter plots for the relevant regression (i.e. the one produced by geom_smooth in each scatter plot).
var1 above is just the name of one of the id columns of the melted data and I am facing the same question with facet_grid instad of facet_wrap.
I actually solved this, please see below a worked out example where the dependent variable is var1. This was a time series dataset, please ignore the date part if not relevant for your problem.