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
You can create a new data frame containing the equations for the levels of roi_size
. Here, by
is used:
eqns <- by(df, df$roi_size, lm_eqn)
df2 <- data.frame(eq = unclass(eqns), roi_size = as.numeric(names(eqns)))
Now, this data frame can be used for the geom_text
function:
geom_text(data = df2, aes(x = 1.5, y = 2.2, label = eq, family = "serif"),
color = 'blue', parse = TRUE)