在 R 中的 cowplot::gridplot 中向子图添加标签

Adding labels to subplots in cowplot::gridplot in R

我正在使用网格图绘制几个图形,如下所示。

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)

如何在每个地块上添加子 headers/titles。例如 Sample#1、Sample#2 等?

您可以使用 labels 和所有相关参数,例如 hjust 根据需要移动文本:

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