误差棒点图简介
误差棒是用来反映数据不确定性的,以被测量值的算数平均值为重点。一般使用在散点图中,以线段的方式显示出来。误差棒长度越长代表误差越大,反之则误差越小。
标签:#微生物组数据分析 #MicrobiomeStatPlots #误差棒点图 #R语言可视化 #Error bar plot
作者:First draft(初稿):Defeng Bai(白德凤);Proofreading(校对):Ma Chuang(马闯) and Jiani Xun(荀佳妮);Text tutorial(文字教程):Defeng Bai(白德凤)
引文: Defeng Bai, Chuang Ma, Jiani Xun, Hao Luo, Haifei Yang, Hujie Lyu, et al. 2025. “MicrobiomeStatPlots: Microbiome statistics plotting gallery for meta-omics and bioinformatics.” iMeta 4: e70002. https:///10.1002/imt2.70002
源代码及测试数据链接:
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:///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:///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 packagesuppressWarnings(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 axisplot_data$Factor <- factor(1:12)# Set group and colorplot_data$Group <- factor(rep(c("Group1", "Group2", "Group3", "Group4"), each = 3))# Define color palettecolor_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 bordergeom_errorbar(aes(xmin = Microbes - error_bar, xmax = Microbes + error_bar),width = 0.3, size = 0.8) + # Error bars with adjusted width and sizelabs(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 looktheme(panel.grid.major = element_blank(), # Remove major grid linespanel.grid.minor = element_blank(), # Remove minor grid linesaxis.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#print(p1)
实战2
多组误差棒图
# 加载数据# Load datadf <- read.csv("data/41588_2024_1686_MOESM7_ESM.csv")# 基础绘图# Basic plotp <- 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 appearancep2 <- 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 labelsvline_data <- data.frame(group = c("LOF", "Missense", "Tandem repeat"), # 替换为你的分面组xintercept = c(1, 1, 1) # 对应的垂直线位置)# 完整图形,包括分面和标签# Complete plot with facets and labelsp3 <- 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 plotggsave(filename = "results/Error_bar_plot02.pdf", plot = p3, width = 10, height = 7, useDingbats = FALSE, limitsize = FALSE)
使用此脚本,请引用下文:
