误差棒点图简介
误差棒是用来反映数据不确定性的,以被测量值的算数平均值为重点。一般使用在散点图中,以线段的方式显示出来。误差棒长度越长代表误差越大,反之则误差越小。
标签:#微生物组数据分析 #MicrobiomeStatPlot #误差棒点图 #R语言可视化 #Error bar plot
作者:First draft(初稿):Defeng Bai(白德凤);Proofreading(校对):Ma Chuang(马闯) and Jiani Xun(荀佳妮);Text tutorial(文字教程):Defeng Bai(白德凤)
源代码及测试数据链接:
https://github.com/YongxinLiu/MicrobiomeStatPlot/项目中目录 3.Visualization_and_interpretation/ErrorBarPlot
或公众号后台回复“MicrobiomeStatPlot”领取
这是北京大学Wang Wei团队2023年发表于Global Change Biology(Zhang et al., 2023)上的一篇论文,题目为:Soil fertility shifts the relative importance of saprotrophic and mycorrhizal fungi for maintaining ecosystem stability. https://doi.org/10.1111/gcb.16540
图 3 | 区域调查和(c,d)全球调查中生态系统稳定性的控制因素。
多元回归分析揭示了生态系统稳定性的生物和非生物预测因子的相对重要性。显示了每个变量的标准化回归系数及其95%置信区间。C:N,土壤碳氮比;MAT,年平均气温;STN,土壤总氮;STP,土壤总磷。显著性水平:p<.05,p<.01,p<.001。
结果
考虑到植物多样性、气候、土壤特性和地理距离后,这些正相关关系仍然存在(图3a、b)。在考虑环境因素后,它们对生态系统稳定性的影响得以维持(图3c,d)。在考虑了植物和环境变量后,真菌官能团内的多样性对生态系统稳定性的显著影响得以维持,这表明微生物多样性的稳定作用在现实世界的生态系统中是不可替代的(图3)。
这是来自于加拿大多伦多大学儿童医院的Stephen W. Scherer团队2024年发表于Nature Genetics上的一篇论文。题目为:Comprehensive whole-genome sequence analyses provide insights into the genomic architecture of cerebral palsy. https://doi.org/10.1038/s41588-024-01686-x
图 2 | 新SNVs/indels和大TR的基因集分析。
三个面板代表了从头LOF变体(负载分析)、从头错义变体(负担分析)和大TR(传播测试)的基因集水平分析结果。颜色表示不同的队列,点表示用Fisher精确检验作为OR估计的效应大小,误差条表示95%的CI(Inova、CHILD和CP分别为n=203178和314)。显著结果用星号标记,即Benjamini–Hochberg FDR<10%的结果。AD,常染色体显性遗传。
结果
在与CP和NDD相关的基因集中,在CP队列中观察到ExpansionHunter Denovo在与轴突引导和突触后密度相关的基因中检测到的大TR的过度传递(图2和补充表4)。
源代码及测试数据链接:
https://github.com/YongxinLiu/MicrobiomeStatPlot/
或公众号后台回复“MicrobiomeStatPlot”领取
软件包安装
# 基于CRAN安装R包,检测没有则安装
p_list = c("ggplot2", "RColorBrewer")
for(p in p_list){if (!requireNamespace(p)){install.packages(p)}
library(p, character.only = TRUE, quietly = TRUE, warn.conflicts = FALSE)}
# 加载R包 Load the package
suppressWarnings(suppressMessages(library(ggplot2)))
suppressWarnings(suppressMessages(library(RColorBrewer)))
实战1
单组误差棒图
# Load data
# 读入数据
df <- read.csv("data/test_otu.csv", row.names = 1)
# Construct dataframe
# 处理数据
plot_data <- df[101:112, c(7, 12)]
colnames(plot_data) <- c("Microbes", "error_bar")
plot_data <- as.data.frame(scale(plot_data))
plot_data$error_bar <- plot_data$error_bar / 5
# Select data for Y axis
plot_data$Factor <- factor(1:12)
# Set group and color
plot_data$Group <- factor(rep(c("Group1", "Group2", "Group3", "Group4"), each = 3))
# Define color palette
color_palette <- brewer.pal(4, "Set1")
# Plot
# 绘图
p1 <- ggplot(plot_data, aes(x = Microbes, y = Factor, color = Group)) +
geom_point(size = 4, shape = 21, fill = "white", stroke = 0.8) + # Larger point size with border
geom_errorbar(aes(xmin = Microbes - error_bar, xmax = Microbes + error_bar),
width = 0.3, size = 0.8) + # Error bars with adjusted width and size
labs(y = "Index", x = "Effects (%)") +
geom_vline(xintercept = 0, linetype = "dashed", color = "black", size = 0.7) +
geom_hline(yintercept = c(3.5, 6.5, 9.5), linetype = "dashed", color = "black", size = 0.7) +
scale_x_continuous(expand = c(0, 0), limits = c(-2, 2)) +
scale_color_manual(values = color_palette) +
theme_classic(base_size = 14) + # Use a classic theme for a clean look
theme(
panel.grid.major = element_blank(), # Remove major grid lines
panel.grid.minor = element_blank(), # Remove minor grid lines
axis.text = element_text(color = 'black', size = 12),
axis.title = element_text(size = 14, face = "bold"),
legend.position = "top",
legend.title = element_text(size = 14, face = "bold"),
legend.text = element_text(size = 12),
plot.title = element_text(size = 16, face = "bold", hjust = 0.5),
panel.border = element_rect(color = "black", fill = NA, size = 0.8) # Add border around the plot
)
# Save the plot
# 图保存
ggsave(filename = "results/Error_bar_plot01.pdf", plot = p1, width = 8, height = 6, useDingbats = FALSE, limitsize = FALSE)
# Display the plot
实战2
多组误差棒图
# 加载数据
# Load data
df <- read.csv("data/41588_2024_1686_MOESM7_ESM.csv")
# 基础绘图
# Basic plot
p <- ggplot(data = df, aes(x = OR, y = geneset, fill = set)) +
geom_errorbarh(aes(xmin = lower, xmax = upper, color = set), height = 0, show.legend = FALSE, position = position_dodge(0.9)) +
geom_point(position = position_dodge(0.9), aes(color = set), size = 3, show.legend = TRUE)
# 美化图形
# Enhance plot appearance
p2 <- ggplot(data = df, aes(x = OR, y = geneset, fill = set, color = set)) +
geom_errorbarh(aes(xmin = lower, xmax = upper), height = 0, show.legend = TRUE, position = position_dodge(0.9)) +
geom_point(position = position_dodge(0.9), size = 3) +
geom_vline(xintercept = 0.5, linetype = "dashed", color = "gray", size = 0.7) +
scale_fill_manual(values = c("#DC0000FF", "#3C5488FF", "#00A087FF", "gray")) +
scale_color_manual(values = c("#DC0000FF", "#3C5488FF", "#00A087FF", "gray")) +
theme(panel.grid = element_blank(),
panel.background = element_blank(),
panel.border = element_rect(color = "gray", fill = NA, size = 0.7),
axis.text.x = element_text(size = 12, color = "black", angle = 0, margin = margin(t = 2)), # 设置X轴刻度文本与刻度线距离
axis.text.y = element_text(size = 12, colour = "black"),
axis.title.y = element_text(size = 14),
axis.ticks.length = unit(0.1, "cm")) +
labs(x = "", y = "") +
guides(color = guide_legend(title = NULL), fill = guide_legend(title = NULL))
# 分面及分面标签
# Facet and facet labels
vline_data <- data.frame(
group = c("LOF", "Missense", "Tandem repeat"), # 替换为你的分面组
xintercept = c(1, 1, 1) # 对应的垂直线位置
)
# 完整图形,包括分面和标签
# Complete plot with facets and labels
p3 <- ggplot(data = df, aes(x = OR, y = geneset, fill = set, color = set)) +
geom_errorbarh(aes(xmin = lower, xmax = upper), height = 0, show.legend = TRUE, position = position_dodge(0.9)) +
geom_point(position = position_dodge(0.9), size = 3) +
geom_vline(data = vline_data, aes(xintercept = xintercept), linetype = "dashed", color = "black", size = 0.7) +
facet_wrap(~variant) +
# geom_text(data = ann_text,label="*") +
scale_fill_manual(values = c("#DC0000FF", "#3C5488FF", "#00A087FF", "gray")) +
scale_color_manual(values = c("#DC0000FF", "#3C5488FF", "#00A087FF", "gray")) +
theme(panel.grid = element_blank(),
panel.background = element_blank(),
panel.border = element_rect(color = "gray", fill = NA, size = 0.7),
axis.text.x = element_text(size = 12, color = "black", angle = 0, margin = margin(t = 2)),
axis.text.y = element_text(size = 12, colour = "black"),
axis.title.y = element_text(size = 14),
axis.ticks.length = unit(0.1, "cm"),
legend.position = "top",
legend.direction = "horizontal",
strip.background = element_rect(color = "gray")) +
geom_text(aes(label = significant, x = upper + 0.5)) +
labs(x = "", y = "") +
guides(color = guide_legend(title = NULL), fill = guide_legend(title = NULL))
# 保存图形
# Save plot
ggsave(filename = "results/Error_bar_plot02.pdf", plot = p3, width = 10, height = 7, useDingbats = FALSE, limitsize = FALSE)
使用此脚本,请引用下文:
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群供大佬合作交流。技术问题寻求帮助,首先阅读《如何优雅的提问》学习解决问题思路,仍未解决群内讨论,问题不私聊,帮助同行。
点击阅读原文