plot_density_by_treatment.Rd
This function creates a list of ggplot density plots for specified variables by treatment groups.
plot_density_by_treatment(
data,
var_map,
treatment_var,
show_legend = TRUE,
theme_use = ggplot2::theme_minimal(),
...
)
A data frame containing the variables to plot and a treatment variable.
A named list mapping the column names in the data to display names for plotting.
A named vector where the name is the treatment column in the data and the value is the legend title.
A logical value indicating whether to show the legend. Defaults to TRUE.
ggplot2 theme. Defaults to ggplot2::theme_minimal()
.
Additional arguments to be passed to geom_density
.
A list of ggplot objects for each variable in var_map
.
if (FALSE) {
data(mtcars)
data <- mtcars %>%
dplyr::select(mpg, cyl) %>%
dplyr::rowwise() %>%
dplyr::mutate(treatment = sample(c(0,1), 1, replace = TRUE)) %>%
dplyr::ungroup()
plots <- plot_density_by_treatment(
data = data,
var_map = list("mpg" = "Var 1",
"cyl" = "Var 2"),
treatment_var = c("treatment" = "Treatment Name\nin Legend")
)
}