Search code examples
rcowplot

Adding labels to subplots in cowplot::gridplot in R


I am plotting several figures using grid plot like following.

p.list <- list()
for (i in 1:length(paths)){
  p <- plotQC(get(paste0("sce_",i)), type = "highest-expression")
  p.list[[i]] <- p
}
cowplot::plot_grid(plotlist = p.list)

How to add sub headers/titles on each plot. for example Sample#1, Sample#2 etc?


Solution

  • You may use labels and all the related parameters, such as hjust to shift the text as needed:

    l <- list(qplot(1:10, 1:10) , qplot(1:10, (1:10)^2))
    plot_grid(plotlist = l, labels = paste0("Sample #", 1:2), hjust = -1)
    

    enter image description here