I am plotting geom_points on multiple facets and would like to annotate R^2 on each facet (preferably on the facet_label rather on the graph.) I have found some code here wh
The following seems to work
lm_eqn = function(df){
m = lm(ln_x ~ ln_y, data=df)
eq <- substitute(~~R^2~"="~r2,
list(r2 = format(summary(m)$r.squared, digits = 3)))
c(eq = as.character(as.expression(eq)));
}
Create new data frame containing R^2 for each roi_size
labeldata <- ddply(df,.(roi_size),lm_eqn )
and geom_text becomes
geom_text(data=labeldata,aes(x=1.5,y=2.2,label=eq,family="serif"), color='blue', parse=TRUE)