我們很久之前發(fā)布過這樣的帖子(玩轉(zhuǎn)單細(xì)胞(2):Seurat批量做圖修飾更鲁,Seurat單細(xì)胞基因顯著性檢驗(yàn)函數(shù)及批量添加顯著性)霎箍。都解決了一定的問題,但是不夠完美澡为,且小伙伴說某些地方有報(bào)錯漂坏。所以我們這里重新探究一下,如何批量修飾seurat包中Vlnplot作圖媒至,以及批量添加顯著性顶别,其實(shí)很簡單,只用到一個&連接符拒啰。在某些帖子中我們也講過驯绎。但是,本貼最最重要的是我們要復(fù)現(xiàn)一篇Cell子刊中的圖表谋旦,基本圖形還是Vlnplot展示基因表達(dá)剩失,特點(diǎn)是在圖的上部展示了表達(dá)基因的細(xì)胞比例:這幅圖的難點(diǎn)在于獲取餅圖數(shù)據(jù)屈尼,以及將其對應(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"))
#單個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"))
多個基因批量修飾:
#多個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)方式:
#三組,多個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"))
接下來就是復(fù)現(xiàn)文章中的圖表了乞巧,也比較簡單涨椒,主題就是上面的這些小提琴圖,只不過需要計(jì)算一下比例绽媒,做一下餅圖添加上去就可以了蚕冬。一步步也能夠完成,餅圖可以參考余老師的ggimage(https://cosx.org/2017/03/ggimage/)是辕。但是考慮到每次換個基因就需要重新來一遍囤热,流程繁瑣,所以本著我們號“麻煩自己获三,方便他人”的精神旁蔼,干脆整成一個小函數(shù)得了,這樣小伙伴就不用考慮中間亂七八糟的過程了疙教!
我們先看看函數(shù)主體: 視頻解說參考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"))
多組比較可視化也是沒有問題的:
ks_VlnExp(object = uterus, group="orig.ident", group_order=c("HC","AEH","EEC"), features="ANXA1",comparisons=c(my_comparisons1,my_comparisons2,my_comparisons3))
沒毛病贞谓,非常完美限佩!希望對你有所幫助!