Set up label.color with the same colors as the cluster colors in Seurat DimPlot() ?
1
0
Entering edit mode
17 months ago
Ondina ▴ 100

Hello,

I want to show on my UMAP, using the DimPlot() function, the same colors on the text labels as the cluster colors. If I set up the same colors in the same order as the levels of my idents, the colors do not correspond at all, I guess the order in which the labels are organised inside the DimPlot() are not the same as the levels of the identities which are given for coloring the cells.

This is my code:

DimPlot(S2, label = T, repel = T, cols = list, label.size = 5, pt.size = 1, label.box = F, label.color = list) 

Is there a way to make the colors coincide?

I also opened an github issue on this subject here

I'm sure it's something really obvious to do but I can't find it ...

Thank you!

image

seurat scRNA-seq • 3.9k views
ADD COMMENT
1
Entering edit mode

What does list contain? Also, consider not naming variables list given that the list() function exists.

ADD REPLY
1
Entering edit mode

I wrote "list" just for the example, my variable is called differently.

It contains a list of colors

 l <-  c("#F8766D" ,"#E38900", "#C49A00", "#99A800", "#53B400" ,"#00BC56" ,"#00C094" ,"#00BFC4" ,"#00B6EB" ,"#06A4FF","#A58AFF" ,"#DF70F8" ,"#FB61D7" ,"#FF66A8")

I also tried formatting the list by specifying the cluster name with its color name, but it's ineffective, like this:

   l <-  c('c2' = 'red', 'c3' = 'grey', 'c4' = 'grey' ... )
ADD REPLY
0
Entering edit mode

What happens if you don't pass the label.color argument?

ADD REPLY
0
Entering edit mode

The labels stay black

ADD REPLY
0
Entering edit mode

I think the GitHub issue is the place to watch - the source code is too complicated for me to suggest a workaround, maybe the developers can add an option or suggest a quickfix.

ADD REPLY
4
Entering edit mode
17 months ago

Bit of an oversight. Try:

DimPlot(S2, label = T, repel = T, cols = list, label.size = 5, pt.size = 1, 
        label.box = F, label.color = list, order = unique(S2$orig.ident))

Should get the colors to match up, though the order of the legend will change. Ultimate issue is that it's plotting whatever data comes first in the matrix whereas the labels are being tossed on centroids of the respective group, not necessarily in the same order.

ADD COMMENT
0
Entering edit mode

Oh thank you, I didn't knew the "order" parameter worked on the colors too, this is perfect!

ADD REPLY

Login before adding your answer.

Traffic: 2552 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