BioF3 FigCode · SCI 绘图代码集
GSEA 瀑布图(NES Waterfall)
分类:功能富集 | 依赖包:ggplot2
解决的生物学问题
哪些通路在实验组中被显著激活或抑制?激活与抑制的通路数量是否平衡?
应用场景
- GSEA 结果全景展示
- 对比激活与抑制通路
- 多数据库(GO/KEGG/Hallmark)结果汇总
- 筛选后续验证的候选通路
输入数据格式
GSEA 结果表(NES, p.adjust, Description)
关键参数
- 展示通路数(top 5-10 each direction)
- NES 阈值过滤
- p.adjust 阈值(0.05 / 0.25)
- 条形颜色方案(红蓝对比)
快速开始
1. 直接在线运行
打开 FigCode 在线绘图,点击本工具卡片的"在线绘图"按钮即可用内置示例数据出图,零环境配置。
2. 本地复现
下载脚本和示例数据,本地 RStudio 运行:
# 下载
curl -O https://<your-site>/figcode/scripts/gsea-waterfall.R
curl -O https://<your-site>/figcode/data/gsea-waterfall.csv
3. 安装依赖
# CRAN 包
install.packages(c("ggplot2"))
# Bioconductor 包(如需)
# BiocManager::install(c())
完整代码
library(ggplot2)
# --- Demo data ---
set.seed(42)
pathways <- c("Oxidative phosphorylation", "Cell cycle", "DNA repair",
"Fatty acid metabolism", "mTOR signaling", "Apoptosis",
"Immune activation", "Wnt signaling", "Notch signaling",
"Hedgehog signaling", "TGF-beta signaling", "p53 pathway")
top_terms <- data.frame(
Description = pathways,
NES = c(2.3, 1.9, 1.7, 1.5, 1.3, 1.1, -1.2, -1.4, -1.6, -1.8, -2.0, -2.4),
p.adjust = runif(12, 0.001, 0.04)
)
top_terms$direction <- ifelse(top_terms$NES > 0, "Activated", "Suppressed")
# --- Plot ---
ggplot(top_terms, aes(x = reorder(Description, NES), y = NES, fill = direction)) +
geom_col(width = 0.7) + coord_flip() +
scale_fill_manual(values = c(Activated="#dc2626", Suppressed="#2563eb")) +
labs(x = NULL, y = "Normalized Enrichment Score (NES)", title = "GSEA NES Waterfall") +
theme_classic() +
theme(legend.position = "top")
替换为自己的数据
脚本中以 # --- Demo data --- 标注的段落是示例数据生成代码。替换为自己的数据时,保持列名一致即可:
- 输入格式:GSEA 结果表(NES, p.adjust, Description)
- 使用
read.csv()/readRDS()读取本地文件
延伸阅读
- 相关教程:GSEA 瀑布图 完整流程
- 出现 bug?欢迎在 FigCode 页面 点击对应卡片,在评论区留言。