今天我們這一期要說的內(nèi)容其實很簡單灾茁,之前我們在寫其他內(nèi)容的時候或多或少的提到過窜觉,但是奈何問的人實在很多,次數(shù)也很多北专,所以索性這里出個帖子禀挫,將這個問題直接綜合起來講一下。這個內(nèi)容就是我們用seurat作圖的時候拓颓,例如Dimplot做降維圖的時候语婴,如何指定cluster的顏色。用Vlnplot或者Dotplot作圖的時候如何設(shè)置順序。那么最后還有一個小問題就是seurat V5 object的使用砰左,其實seurat的更新并不是很可怕匿醒,遇到那里有錯,解決就可以了缠导!
一廉羔、指定降維圖中cluter的顏色
我們使用Dimplot做將降維圖的時候,每個cluster或者celltype的顏色是利用cols參數(shù)設(shè)置的僻造,那么很多小伙伴就提出問題憋他,我修改顏色的時候如何指定呢。很簡單:
#==========================================================================
# 1髓削、cluster/celltype指定顏色設(shè)置
#==========================================================================
library(Seurat)
#指定cluster/celltype的顏色
Idents(uterus) <- "seurat_clusters"
clusterCols <- c("#843C39", "#8C6D31", "#E6550D", "#3182BD", "#54990F",
"#BD9E39", "#E7BA52", "#31A354", "#E41A1C", "#6BAED6",
"#9ECAE1", "#AD494A", "#A1D99B", "#C7E9C0", "#99600F",
"#C3BC3F", "#D6616B", "#FF7F00", "#1B9E77", "#FDAE6B",
"#66A61E", "#F1788D", "#E6550D", "#E7969C")
names(clusterCols) <- c(0:24)
DimPlot(uterus, group.by='seurat_clusters', cols=clusterCols, pt.size=1, raster=F, label = T)+NoLegend()
unique(uterus$celltype)
# [1] "Smooth muscle cells" "Lymphocytes"
# [3] "Unciliated epithelial cells" "Stromal fibroblasts"
# [5] "Ciliated epithelial cells" "Endothelial cells"
# [7] "Macrophages"
Idents(uterus) <- "celltype"
cols <- c("#843C39", "#E6550D", "#3182BD", "#54990F", "#FF7F00", "#1B9E77", "#FDAE6B")
#將需要的顏色與cell type對應(yīng)
names(cols) <- c("Lymphocytes",
"Stromal fibroblasts",
"Unciliated epithelial cells",
"Endothelial cells",
"Smooth muscle cells",
"Ciliated epithelial cells",
"Macrophages" )
DimPlot(uterus, group.by='celltype', cols=cols, pt.size=1, raster=F, label = T)+NoLegend()
二竹挡、作圖順序的指定
這個問題真的說過無數(shù)次了,設(shè)置順序其實就是factor就可以了立膛!
#==========================================================================
# 2揪罕、seurat作圖修改celltype或者cluster順序
#==========================================================================
library(ggplot2)
#比如我做一個小提琴圖
p1 = VlnPlot(uterus, features = "CD74", pt.size = 0, cols = cols)+theme(axis.title = element_blank(),
axis.text.x = element_text(angle = 90))+NoLegend()
Idents(uterus) <- factor(Idents(uterus), levels = c("Lymphocytes",
"Stromal fibroblasts",
"Unciliated epithelial cells",
"Endothelial cells",
"Smooth muscle cells",
"Ciliated epithelial cells",
"Macrophages" ) )
p2 = VlnPlot(uterus, features = "CD74", pt.size = 0, cols = cols)+theme(axis.title = element_blank(),
axis.text.x = element_text(angle = 90))+NoLegend()
p1|p2
#同樣的設(shè)置后,Dotplot也會隨著自定義順序顯示
markers <- c("ACTA2", "RGS5", #smooth muscle cells---7, 16
"MS4A6A", "CD68","LYZ",#macrophages---13
"CCL5", "STK17B","PTPRC",#lymphocytes---0,3,4,5,6,14,15,17,23,18,19
"DCN", "COL6A3", "LUM",#stromal fibroblasts---2,20
"PECAM1","PCDH17", "VWF",#endothelial cells---8,11,22
"EPCAM", "CDH1",#(unciliated)epithelial cells---1,9,21
"FOXJ1","CDHR3","DYDC2")#(ciliated)epithelial cells---10,12
DotPlot(uterus, features = markers)+theme_bw()+theme(axis.title = element_blank(),
axis.text.x = element_text(angle = 90))
#對于split的
p3 = DimPlot(uterus, split.by = "orig.ident")
#可以看到celltype legend的排列是按照我們設(shè)置的順序宝泵。但是我們需要設(shè)置分組的順序
uterus$orig.ident <- factor(uterus$orig.ident, levels = c("HC","EEC","AEH"))
p4 = DimPlot(uterus, split.by = "orig.ident")
p3/p4
更多請參考:https://mp.weixin.qq.com/s/7KeJi0mhCmHFsAucGWnWwQ