diff --git a/R/combine_cluster_plots_and_save.R b/R/combine_cluster_plots_and_save.R index 007f1e624c30c8b4a7a1e1a403d475bc61dc7a20..b8afff087982981f21aaccff01c1806c38fe38e0 100644 --- a/R/combine_cluster_plots_and_save.R +++ b/R/combine_cluster_plots_and_save.R @@ -12,15 +12,17 @@ #' @param h The height of the plot. Default is 'cm_height'. #' @return combined plot #' @import ggplot2 +#' @importFrom cowplot get_legend plot_grid #' @export combine_cluster_plots_and_save <- function(plot_list, cluster, out_path = path, w = cm_width, h = cm_height) { dir.create(out_path, showWarnings = FALSE) - combo_pl <- ggpubr::ggarrange(plotlist = plot_list, - ncol = 3, align = "hv", common.legend = TRUE, - legend = "bottom") - combo_pl <- ggpubr::annotate_figure(combo_pl, top = ggpubr::text_grob( - paste("Cluster:", cluster), vjust = 0.5, x = 0.01, hjust = 0)) + combo_pl <- cowplot::plot_grid(plotlist = plot_list, + ncol = 3, align = "hv") + legend <- cowplot::get_legend(plot_list[[3]]) + combo_pl_with_legend <- cowplot::plot_grid(combo_pl, legend, + ncol = 1, rel_heights = c(1, .1)) + + ggtitle(paste("Cluster:", cluster)) ggsave(file.path(out_path, paste0("Cluster_overview_", cluster, ".pdf")), combo_pl, width = w, height = h, units = "cm") return(combo_pl)