facet_R2: facet_R2

View source: R/facet_R2.R

facet_R2R Documentation

facet_R2

Description

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.

Usage

facet_R2(df, y, x, by)

Arguments

df

data frame

y

y axis name

x

x axis name

by

name of the factor used to split the data into facets.

Value

a data frame containing the R^2 values for the linear model from each facet.

Examples


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


baynec2/biolabr documentation built on Aug. 8, 2022, 12:02 a.m.