Split a data frame on a single factor and create a plot from each chunk.
Each plot is labeled with the value of sp
using ggplot2::facet_wrap()
.
See examples.
split_plot(df, fun, sp = get_split_col(df), labeller = label_tex, ...)
Data frame to split and plot.
Function to use to plot.
Character name of column to split; if df
is a
grouped data frame, leave this argument missing and the; regardless
of how this is specified, sp
should name a single column
split column will be determined from the groups.
A labeller to pass to ggplot2::facet_wrap()
; by default,
the value is printed on the strip with label_tex()
.
passed to fun
A list of plots, one for each grouping in sp
.
df <- pmplots_data_obs()
require(dplyr)
#> Loading required package: dplyr
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
df %>% group_by(STUDYc) %>% split_plot(dv_pred)
#> $SAD
#> `geom_smooth()` using formula = 'y ~ x'
#> Warning: Removed 1 row containing missing values or values outside the scale range
#> (`geom_smooth()`).
#>
#> $MAD
#> `geom_smooth()` using formula = 'y ~ x'
#>
#> $Renal
#> `geom_smooth()` using formula = 'y ~ x'
#>
#> $Hepatic
#> `geom_smooth()` using formula = 'y ~ x'
#>