This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Set up label.color with the same colors as the cluster colors in Seurat DimPlot() ?

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

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

The labels stay black

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.

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

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' ... )

1 answer

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.

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

Log in to answer this question.