Consistent cluster coloring
1
0
Entering edit mode
6 months ago
solo.albif • 0

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 • 588 views
ADD COMMENT
2
Entering edit mode
6 months ago
bk11 ★ 3.0k

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

ADD COMMENT
0
Entering edit mode

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!

ADD REPLY

Login before adding your answer.

Traffic: 1935 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6