Skip to content
Snippets Groups Projects
Commit ea261822 authored by Simeon's avatar Simeon
Browse files

Update combine_cluster_plots_and_save.R

parent b2eb26b1
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment