diff --git a/R/combine_cluster_plots_and_save.R b/R/combine_cluster_plots_and_save.R index 828a5955ce613eefbeb0efd96b0ac6045b05f044..afeb5e8f236bd254920972da058ae0c9e9a942c9 100644 --- a/R/combine_cluster_plots_and_save.R +++ b/R/combine_cluster_plots_and_save.R @@ -17,12 +17,27 @@ 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 <- cowplot::plot_grid(plotlist = plot_list, + combo_pl <- cowplot::plot_grid(plot_list[[1]] + theme(legend.position = "none"), + plot_list[[2]] + theme(legend.position = "none"), + plot_list[[3]] + theme(legend.position = "none"), 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)) + legend <- cowplot::get_legend(plot_list[[3]] + + guides(fill = guide_legend(nrow = 1)) + + theme(legend.position = "bottom")) + title <- ggdraw() + + draw_label( + paste("Cluster:", cluster), + fontface = 'bold', + x = 0, + hjust = 0 + ) + + theme( + # add margin on the left of the drawing canvas, + # so title is aligned with left edge of first plot + plot.margin = margin(0, 0, 0, 7) + ) + combo_pl_with_legend <- cowplot::plot_grid(title, combo_pl, legend, + ncol = 1, rel_heights = c(.1, 1, .1)) ggsave(file.path(out_path, paste0("Cluster_overview_", cluster, ".pdf")), combo_pl_with_legend, width = w, height = h, units = "cm") return(combo_pl_with_legend)