4. Plotting multiple UMAPs

Here is a trick to plotting multiple UMAPS in a tile. It uses the function plot_grid() from the cowplot package. There are several ways of doing this but cowplot is my personal favorite. :cow:

library(cowplot)
gene_name <- "Sox17"
gene_id <- rowData(sce)[which(rowData(sce)[,2] %in% gene_name),1]
a <- plotReducedDim(object = sce, dimred="umap", colour_by=gene_id) + labs(title = gene_name) + theme(legend.title = element_blank(), legend.position="top")

gene_name <- "Sox9"
gene_id <- rowData(sce)[which(rowData(sce)[,2] %in% gene_name),1]
b <- plotReducedDim(object = sce, dimred="umap", colour_by=gene_id) + labs(title = gene_name) + theme(legend.title = element_blank(), legend.position="top")

gene_name <- "Sox2"
gene_id <- rowData(sce)[which(rowData(sce)[,2] %in% gene_name),1]
c <- plotReducedDim(object = sce, dimred="umap", colour_by=gene_id) + labs(title = gene_name) + theme(legend.title = element_blank(), legend.position="top")

gene_name <- "Sox3"
gene_id <- rowData(sce)[which(rowData(sce)[,2] %in% gene_name),1]
d <- plotReducedDim(object = sce, dimred="umap", colour_by=gene_id) + labs(title = gene_name) + theme(legend.title = element_blank(), legend.position="top")

plot_grid(a,b,c,d)

How it works:

  1. I define the gene_name I want to plot
  2. I look up the ensemble id for that gene and call it gene_id
  3. I do plotReducedDim for the umap of that gene and instead of plotting it I assign the plot to a variable a, b, c, …
  4. Then once I’ve defined all my plots plot_grid will tile each of those plots. You could call them anything. for example, I could have done plot1 <-, plot2 <-, … instead of a, b, c, …