不同分类级别堆叠柱状图简介
堆叠柱状图常用于展示微生物不同分类级别组成。包括用堆叠柱状图直观的比较不同分组之间的微生物组成变化。而如果没有分组,只想展示一下不同分类级别微生物的组成情况,可以将不同分类级别的微生物组成放在一张图中展示,并给不同分类级别组成不同的着色加以区分。这样就能直观的了解不同分类级别主要的组成是什么。
标签:#微生物组数据分析 #MicrobiomeStatPlot #不同分类级别堆叠柱状图 #R语言可视化 #Multi-levels StackPlot
作者:First draft(初稿):Defeng Bai(白德凤);Proofreading(校对):Ma Chuang(马闯) and Jiani Xun(荀佳妮);Text tutorial(文字教程):Defeng Bai(白德凤)
源代码及测试数据链接:
https://github.com/YongxinLiu/MicrobiomeStatPlot/项目中目录 3.Visualization_and_interpretation/StackPlot_Multi_levels
或公众号后台回复“MicrobiomeStatPlot”领取
这是内蒙古农业大学张和平和孙志宏团队2023年发表于Nature Microbiology上的一篇论文用到的堆叠柱状图,论文的题目为:A high-quality genome compendium of the human gut microbiome of Inner Mongolians. https://doi.org/10.1038/s41564-022-01270-1.
图 2b | IMGG 数据集在门、纲、目和科级别的分类分布。
每个分类级别仅显示前五个分类单元,其余分类单元归类为“其他”。
结果
回收的 MGS 在分类学上归属于 11 个门、14 个纲、30 个目和 40 个科,涵盖 220 个属(图 2b 和补充表 8)。
源代码及测试数据链接:
https://github.com/YongxinLiu/MicrobiomeStatPlot/
或公众号后台回复“MicrobiomeStatPlot”领取
软件包安装
# 基于CRAN安装R包,检测没有则安装 Installing R packages based on CRAN and installing them if they are not detected
p_list = c("ggplot2", "tidyverse")
for(p in p_list){if (!requireNamespace(p)){install.packages(p)}
library(p, character.only = TRUE, quietly = TRUE, warn.conflicts = FALSE)}
# 加载R包 Loading R packages
suppressWarnings(suppressMessages(library(ggplot2)))
suppressWarnings(suppressMessages(library(tidyverse)))
实战
# Load data
data <- read.table("data/data.txt", header = TRUE, sep = "\t", comment.char = "")
# 定义 Phylum 级别的配色方案(Define colors)
# 批量生成颜色
# 自定义颜色 (Custom colors)
colors <- c("#ccece6","#bfd3e6","#ccebc5","#fdbb84","#a6bddb","#c994c7",
"#99d8c9","#9ebcda","#a8ddb5","#fc8d59","#74a9cf","#67a9cf","#df65b0","#f768a1","#78c679","#41b6c4",
"#41ae76","#8c6bb1","#4eb3d3","#ef6548","#3690c0","#3690c0","#e7298a","#dd3497","#41ab5d","#1d91c0",
"#238b45","#88419d","#2b8cbe","#d7301f","#0570b0","#02818a","#ce1256","#ae017e","#238443","#225ea8",
"#006d2c","#810f7c","#0868ac","#b30000","#045a8d","#016c59","#980043","#7a0177","#006837","#253494"
)
# 为每个 Phylum 级别分配唯一的颜色(Assign a unique color to each Phylum level)
get_fill_colors <- function(data, colors) {
taxa_samples <- unique(interaction(data$Taxa, data$Sample, sep = "_"))
colors <- setNames(
colors[seq_along(taxa_samples)], # 从颜色池中选择足够的颜色
taxa_samples
)
return(colors)
}
# 处理数据,添加 Fill 列(Process data and add Fill column)
data <- data %>%
mutate(Fill = interaction(Taxa, Sample, sep = "_")) # Taxa 和 Sample 组合
# 分配颜色 (Assign Color)
fill_colors <- get_fill_colors(data, colors)
data = data %>%
mutate(Sample = ordered(Sample,
levels=c("Phylum","Class","Order","Family","Genus"
)))
# 绘制堆叠柱状图 (Plot)
p <- ggplot(data, aes(x = Sample, y = Abundance, fill = Fill)) +
geom_bar(stat = "identity", position = "stack") +
scale_fill_manual(values = fill_colors) +
labs(x =NULL, y="Relative abundance (%)", fill = "Taxa-Sample") +
#theme_minimal() +
theme_bw()+
theme(axis.text.x = element_text(angle = 45, hjust = 1))
# 保存为 PDF 文件 (Save as PDF)
pdf("results/microbiome_composition_different_levels.pdf", width = 10, height = 6)
print(p)
dev.off()
#> png
#> 2
使用此脚本,请引用下文:
Yong-Xin Liu, Lei Chen, Tengfei Ma, Xiaofang Li, Maosheng Zheng, Xin Zhou, Liang Chen, Xubo Qian, Jiao Xi, Hongye Lu, Huiluo Cao, Xiaoya Ma, Bian Bian, Pengfan Zhang, Jiqiu Wu, Ren-You Gan, Baolei Jia, Linyang Sun, Zhicheng Ju, Yunyun Gao, Tao Wen, Tong Chen. 2023. EasyAmplicon: An easy-to-use, open-source, reproducible, and community-based pipeline for amplicon data analysis in microbiome research. iMeta 2: e83. https://doi.org/10.1002/imt2.83
Copyright 2016-2024 Defeng Bai baidefeng@caas.cn, Chuang Ma 22720765@stu.ahau.edu.cn, Jiani Xun 15231572937@163.com, Yong-Xin Liu liuyongxin@caas.cn
猜你喜欢
iMeta高引文章 fastp 复杂热图 ggtree 绘图imageGP 网络iNAP
iMeta网页工具 代谢组MetOrigin 美吉云乳酸化预测DeepKla
iMeta综述 肠菌菌群 植物菌群 口腔菌群 蛋白质结构预测
10000+:菌群分析 宝宝与猫狗 梅毒狂想曲 提DNA发Nature
一文读懂:宏基因组 寄生虫益处 进化树 必备技能:提问 搜索 Endnote
16S功能预测 PICRUSt FAPROTAX Bugbase Tax4Fun
生物科普: 肠道细菌 人体上的生命 生命大跃进 细胞暗战 人体奥秘
写在后面
为鼓励读者交流快速解决科研困难,我们建立了“宏基因组”讨论群,己有国内外6000+ 科研人员加入。请添加主编微信meta-genomics带你入群,务必备注“姓名-单位-研究方向-职称/年级”。高级职称请注明身份,另有海内外微生物PI群供大佬合作交流。技术问题寻求帮助,首先阅读《如何优雅的提问》学习解决问题思路,仍未解决群内讨论,问题不私聊,帮助同行。
点击阅读原文