Search code examples
rbioinformaticsrna-seqseurat

Seurat DimPlot - Highlight specific groups of cells in different colours


I apologise for the question that might be very basic, but I cannot figure this out:

I have a Seurat object with 20 different groups of cells (all are defined in metadata and set as active.ident). 10 of them are "treated" and 10 are "untreated" (this info is also in metadata).

R Seurat package

I am trying to make a DimPlot that highlights 1 group at a time, but the colours for "treated" and "untreated" should be different.

my working code highlights both "treated" and "untreated" in the same colour:

DimPlot(integrated, label = T, group.by = "Treat", 
        cells.highlight = WhichCells(integrated, 
                                     idents = c("group1_untreated", "group1_treated")), 
        cols.highlight = c("darkblue", "darkred"), cols = "grey")

What is the right way to do it?

Any suggestions much appreciated!


Solution

  • You can extract the UMAP coordinates from the Seurat object and use ggplot to achieve this.

    library(tidyverse)
    
    umap_tx = integrated@[email protected] %>% 
    as.data.frame() %>% cbind(tx = [email protected]$Treat)
    
    ggplot(umap_tx, aes(x=UMAP_1, y=UMAP_2, color=tx)) + geom_point() + 
    scale_color_manual(values=c("group1_untreated" = "darkblue", 
                                "group1_treated" = "darkred"))