This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Seurat changing order cluster shown in the violin plot

Hi,

I have scRNAseq with total of 33 clusters and I want to select only few of them (eg. cluster 0,3,6,7) and plot specific genes in a violin plot. However ideally I would like to have the clusters shown in specific order in the violin plot (eg. cluster 7,3,6,0) and I tried to follow this post but I am still not getting the results ordered in the way I want.

Specifically my code (the order that I want is 1. Myofibrocytes 2. Erythtrocyes 3. Endothelial cells 4. Fibrocytes :

pbmc2 <- subset( immune.combined , idents = c("Myofibrocytes", "Erythtrocyes", "Endothelial cells", "Fibrocytes"))
pbmc2$celltype.stim <- paste(Idents(pbmc2), pbmc2$sample, sep = "_") #assign the same on a new colunm
pbmc2$celltype <- Idents(pbmc2) # assign the identify to the cell type colunm
Idents(pbmc2) <- "celltype.stim"
levels(pbmc2)

VlnPlot(pbmc2, features = c("Hes1", "Hey1", "Hey2", "Heyl", "Notch1", "Notch2", "Notch3", "Atf4"), 
        pt.size = 0, assay = "RNA",  stack = T, flip = T, fill.by = "ident",split.by = "sample.New", group.by ="celltype") 

and I got this plot : enter image description here

and I try to follow the post:

object_copy <- pbmc2
my_levels <- c("Myofibrocytes", "Erythtrocyes", "Endothelial cells", "Fibrocytes")
Idents(object_copy) <- factor(Idents(object_copy), levels= my_levels)
VlnPlot(object_copy, features = c("Hes1", "Hey1", "Hey2", "Heyl", "Notch1", "Notch2", "Notch3", "Atf4"), 
        pt.size = 0, assay = "RNA",  stack = T, flip = T, fill.by = "ident",split.by = "sample.New", group.by ="celltype") 

I got the same plot . What I am doing wrong? Thank you!

Camilla

r violin seurat

1 answer

You can arrange the order like this before plotting.

pbmc2$celltype <- factor(pbmc2$celltype, levels = c("Myofibrocytes", "Erythtrocyes", "Endothelial cells", "Fibrocytes"))

#then run your VlnPlot function
VlnPlot(pbmc2, features = c("Hes1", "Hey1", "Hey2", "Heyl", "Notch1", "Notch2", "Notch3", "Atf4"), 
        pt.size = 0, assay = "RNA",  stack = T, flip = T, fill.by = "ident",split.by = "sample.New", group.by ="celltype") 

Log in to answer this question.