R/saveDEGcomparePlots.R

Defines functions saveDEGcomparePlots

Documented in saveDEGcomparePlots

#' saveDEGcomparePlots
#'
#' @description Save each of the plots generated by PlotDEGenes to its own
#'   appropriately scaled file.
#'
#' @param plot_list List of group DEGs as generated by PlotDEGenes
#' @param path Location in which to save the plots. Default = ~/
#' @param format Filetype to save the file to.  Save options as ggsave,
#'   that is "eps", "ps", "tex" (pictex), "pdf", "jpeg", "tiff", "png",
#'   "bmp", "svg" or "wmf".  Default = png
#'
#' @importFrom ggplot2 ggsave coord_flip
#' @importFrom glue glue
#' @importFrom purrr map
#'
#' @return
#' @export
#'
#' @examples
saveDEGcomparePlots <- function(plot_list, path = "~/", format = "png"){
  map(plot_list, function(plots) {
    number_of_genes <- length(unique(plots$data$genes_plot))
    plot_name <- plots$labels$x
    try(
      ggsave(plot = plots + coord_flip(),
             filename = glue("{plot_name}.{format}"),
             path = path,
             height = 0.65 + (0.175 * number_of_genes),
             width = 3.5,
             limitsize = FALSE,
             device = format)
    )
  })
}
milescsmith/DEGcompareR documentation built on May 26, 2019, 9:33 a.m.