我們很久之前發(fā)布過(guò)這樣的帖子(玩轉(zhuǎn)單細(xì)胞(2):Seurat批量做圖修飾,Seurat單細(xì)胞基因顯著性檢驗(yàn)函數(shù)及批量添加顯著性)。都解決了一定的問(wèn)題,但是不夠完美,且小伙伴說(shuō)某些地方有報(bào)錯(cuò)。所以我們這里重新探究一下,如何批量修飾seurat包中Vlnplot作圖,以及批量添加顯著性,其實(shí)很簡(jiǎn)單,只用到一個(gè)&連接符。在某些帖子中我們也講過(guò)。但是,本貼最最重要的是我們要復(fù)現(xiàn)一篇Cell子刊中的圖表,基本圖形還是Vlnplot展示基因表達(dá),特點(diǎn)是在圖的上部展示了表達(dá)基因的細(xì)胞比例:這幅圖的難點(diǎn)在于獲取餅圖數(shù)據(jù),以及將其對(duì)應(yīng)展示在小提琴圖上!

(reference:Distinctive multicellular immunosuppressive hubs confer different intervention strategies for left- and right-sided colon cancers)首先我們演示下Vlnplot作圖的修飾:
#加載R包library(ggpubr)library(ggimage)library(ggplot2)library(Seurat)
#設(shè)置比較-兩兩比較my_comparisons <- list(c("GM", "BM"))
#單個(gè)featuresVlnPlot(human_data, features = "ANXA1", group.by = "group")& theme_bw()& theme(axis.title.x = element_blank(), axis.text.x = element_text(color = 'black',face = "bold", size = 12), axis.text.y = element_text(color = 'black', face = "bold"), axis.title.y = element_text(color = 'black', face = "bold", size = 15), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.border = element_rect(color="black",size = 1.2, linetype="solid"), panel.spacing = unit(0.12, "cm"), plot.title = element_text(hjust = 0.5, face = "bold.italic"), legend.position = 'none')& stat_compare_means(method="t.test",hide.ns = F, comparisons = my_comparisons, label="p.signif", bracket.size=0.8, tip.length=0, size=6)& scale_y_continuous(expand = expansion(mult = c(0.05, 0.1)))& scale_fill_manual(values = c("#FF5744","#208A42"))

多個(gè)基因批量修飾:
#多個(gè)featuresVlnPlot(human_data, features = c("ANXA1","S100A8"), group.by = "group")& theme_bw()& theme(axis.title.x = element_blank(), axis.text.x = element_text(color = 'black',face = "bold", size = 12), axis.text.y = element_text(color = 'black', face = "bold"), axis.title.y = element_text(color = 'black', face = "bold", size = 15), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.border = element_rect(color="black",size = 1.2, linetype="solid"), panel.spacing = unit(0.12, "cm"), plot.title = element_text(hjust = 0.5, face = "bold.italic"), legend.position = 'none')& stat_compare_means(method="t.test",hide.ns = F, comparisons = my_comparisons, label="p.signif", bracket.size=0.8, tip.length=0, size=6)& scale_y_continuous(expand = expansion(mult = c(0.05, 0.1)))& scale_fill_manual(values = c("#FF5744","#208A42"))

多組展示,顯著性檢驗(yàn)我們用的兩兩t檢驗(yàn),可自行修改別的檢驗(yàn)方式:
#三組,多個(gè)features,兩兩比較my_comparisons1 <- list(c("HC", "EEC"))my_comparisons2 <- list(c("EEC", "AEH"))my_comparisons3 <- list(c("HC","AEH"))
#設(shè)置x軸樣本順序Idents(uterus) <- "orig.ident"Idents(uterus) <- factor(Idents(uterus), levels = c("HC","AEH","EEC"))
VlnPlot(uterus, features = c("TXNIP","CXCL1","CCL5","FTH1"), ncol = 2)& theme_bw()& theme(axis.title.x = element_blank(), axis.text.x = element_text(color = 'black',face = "bold", size = 12), axis.text.y = element_text(color = 'black', face = "bold"), axis.title.y = element_text(color = 'black', face = "bold", size = 15), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.border = element_rect(color="black",size = 1.2, linetype="solid"), panel.spacing = unit(0.12, "cm"), plot.title = element_text(hjust = 0.5, face = "bold.italic"), legend.position = 'none')& stat_compare_means(method="t.test",hide.ns = F, comparisons = c(my_comparisons1,my_comparisons2,my_comparisons3), label="p.signif", bracket.size=0.8, tip.length=0, size=6)& scale_y_continuous(expand = expansion(mult = c(0.05, 0.1)))& scale_fill_manual(values = c("#FF5744","#208A42", "#FCB31A"))

接下來(lái)就是復(fù)現(xiàn)文章中的圖表了,也比較簡(jiǎn)單,主題就是上面的這些小提琴圖,只不過(guò)需要計(jì)算一下比例,做一下餅圖添加上去就可以了。一步步也能夠完成,餅圖可以參考余老師的ggimage(https://cosx.org/2017/03/ggimage/)。但是考慮到每次換個(gè)基因就需要重新來(lái)一遍,流程繁瑣,所以本著我們號(hào)“麻煩自己,方便他人”的精神,干脆整成一個(gè)小函數(shù)得了,這樣小伙伴就不用考慮中間亂七八糟的過(guò)程了!
我們先看看函數(shù)主體: 視頻解說(shuō)參考B站:

函數(shù)中部分如果需調(diào)整,自行修改即可,比如檢驗(yàn)方式:首先看看兩組:
ks_VlnExp(object = human_data, group="group",group_order=c("BM","GM"), features="ANXA1",comparisons=list(c("GM", "BM")))

顏色可自定義:
ks_VlnExp(object = human_data, group="group",group_order=c("BM","GM"), features="ANXA1",comparisons=list(c("GM", "BM")), cols=c("#E22C28","#0D6EBA"))

多組比較可視化也是沒(méi)有問(wèn)題的:
ks_VlnExp(object = uterus, group="orig.ident", group_order=c("HC","AEH","EEC"), features="ANXA1",comparisons=c(my_comparisons1,my_comparisons2,my_comparisons3))

沒(méi)毛病,非常完美!希望對(duì)你有所幫助!