Adding R^2 on graph with facets

后端 未结 3 467
一整个雨季
一整个雨季 2020-12-29 12:06

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

3条回答
  •  隐瞒了意图╮
    2020-12-29 12:42

    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)
    

    enter image description here

提交回复
热议问题