R/within_group_plots.R

#' @title Plot and Post-Process Plots
#' @description Take a list of plots to combine them and arrange them within groups
#' @param df A list of ggplot objects
#' @param ip Input Parameter
#' @param ipu Input Parameter Units
#' @param op Output Parameter
#' @param opu Output Parameter Units
#' @return A grob object showing all plots within group together compared to the output parameter
#' @importFrom purrr map2 as_mapper
#' @importFrom dplyr mutate_at
within_group_plots <- function(df, ip, ipu, op, opu) {

  ctf <- as_mapper(~factor(., levels = unique(.)))

  df <- df %>%
    mutate_at(.vars = vars(ip),
              .funs = ctf)

  scale_mm <- compute_scale_vals(df, ip, op)

  map2(ip, ipu, plot_main_effects, df = df, op = op, scale_max_min = scale_mm) %>%
    post_process_plot(output_param = op, var_unit = opu)
}
dylanjm/meplotR documentation built on May 9, 2019, 1:08 a.m.