美文网首页
Seurat包VlnPlot小提琴图修饰---顺带一个函数展示基

Seurat包VlnPlot小提琴图修饰---顺带一个函数展示基

作者: KS科研分享与服务 | 来源:发表于2024-08-26 11:12 被阅读0次

    我们很久之前发布过这样的帖子(玩转单细胞(2):Seurat批量做图修饰Seurat单细胞基因显著性检验函数及批量添加显著性)。都解决了一定的问题,但是不够完美,且小伙伴说某些地方有报错。所以我们这里重新探究一下,如何批量修饰seurat包中Vlnplot作图,以及批量添加显著性,其实很简单,只用到一个&连接符。在某些帖子中我们也讲过。但是,本贴最最重要的是我们要复现一篇Cell子刊中的图表,基本图形还是Vlnplot展示基因表达,特点是在图的上部展示了表达基因的细胞比例:这幅图的难点在于获取饼图数据,以及将其对应展示在小提琴图上!

    (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)
    #设置比较-两两比较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"))
    

    多组展示,显著性检验我们用的两两t检验,可自行修改别的检验方式:

    #三组,多个features,两两比较my_comparisons1 <- list(c("HC", "EEC"))my_comparisons2 <- list(c("EEC", "AEH"))my_comparisons3 <- list(c("HC","AEH"))
    #设置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"))
    

    接下来就是复现文章中的图表了,也比较简单,主题就是上面的这些小提琴图,只不过需要计算一下比例,做一下饼图添加上去就可以了。一步步也能够完成,饼图可以参考余老师的ggimage(https://cosx.org/2017/03/ggimage/)。但是考虑到每次换个基因就需要重新来一遍,流程繁琐,所以本着我们号“麻烦自己,方便他人”的精神,干脆整成一个小函数得了,这样小伙伴就不用考虑中间乱七八糟的过程了!

    我们先看看函数主体: 视频解说参考B站:

    https://www.bilibili.com/video/BV1rGWkeMEwd/?spm_id_from=333.999.0.0&vd_source=05b5479545ba945a8f5d7b2e7160ea34

    函数中部分如果需调整,自行修改即可,比如检验方式:首先看看两组:

    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"))
    
    image.png

    多组比较可视化也是没有问题的:

    ks_VlnExp(object = uterus, group="orig.ident",          group_order=c("HC","AEH","EEC"),          features="ANXA1",comparisons=c(my_comparisons1,my_comparisons2,my_comparisons3))
    
    image.png

    没毛病,非常完美!希望对你有所帮助!

    相关文章

      网友评论

          本文标题:Seurat包VlnPlot小提琴图修饰---顺带一个函数展示基

          本文链接:https://www.haomeiwen.com/subject/nzaokjtx.html