facet_R2 | R Documentation |
This function is used to calculate the R^2 values for different facets. This makes it easy to add R^2 values to different facets of a ggplot using the geom_text function.
facet_R2(df, y, x, by)
df |
data frame |
y |
y axis name |
x |
x axis name |
by |
name of the factor used to split the data into facets. |
a data frame containing the R^2 values for the linear model from each facet.
data(mtcars) R2 = facet_R2(mtcars,y = "mpg",x = "hp",by = "gear") p1 = ggplot(mtcars,aes(mpg,hp))+ geom_point()+ geom_smooth(method = "lm")+ facet_grid(~gear)+ geom_text(data = R2,aes(x = 30, y = 300,label = R2)) p1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.