This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Consistent cluster coloring

Hi,

I am using Seurat to create a UMAP plot with DimPlot, three spatial plots with ImageDimPlot and a heatmap plot with DoHeatmap:

enter image description here enter image description here enter image description here enter image description here enter image description here

I would like to keep the colors of the clusters consistent between plots but I have been so far unable to do that using the cols parameter of DimPlot and ImageDimPlot. I know Seurat is using ggplot2 to print the plots, is there a way I can leverage ggplot2 to assign colors to the clusters?

Thank you very much

r seurat

1 answer

You can basically define the color for your cluster/celltypes and plot them in consistent color in DimPlot, DoHeatmap or any other. Please check an example below:-

library(Seurat)
library(SeuratData)

data=UpdateSeuratObject(pbmc3k.final)
levels(Idents(data))

my_cols=c("Naive CD4 T"="red", "Memory CD4 T"="green", "CD14+ Mono"="purple",  "B" ="black" , "CD8 T" ="pink" ,
          "FCGR3A+ Mono" ="gray",  "NK" ="orange", "DC" ="blue",  "Platelet"="yellow" )

p1 <- DimPlot(data, reduction = "umap", cols=my_cols)

p2 <- DoHeatmap(data, features = c("MS4A1", "CD8A"), group.colors = my_cols)

p1/p2

enter image description here

Wow, this is incredibly easy and straightforward. I tried a lot of different things that did not work but I was close, my mistake was using a list instead of a vector.

Thank you very much!

Log in to answer this question.