BioF3 FigCode · SCI 绘图代码集
GSEA 森林图(NES Forest Plot)
分类:功能富集 | 依赖包:ggplot2
解决的生物学问题
多条候选通路的富集强度和可信度如何排序?哪些通路的 NES 最为稳健?
应用场景
- GSEA 结果多通路对比
- 展示 NES 置信区间
- 筛选稳健富集通路
- 文章 figure 森林图展示
输入数据格式
GSEA 结果表(NES, pvalue, Description, setSize)
关键参数
- 展示通路数(top 10-15)
- NES 点估计及 CI
- pvalue 显著性标记
- setSize 基因集大小
- color 按方向着色(activated / suppressed)
快速开始
1. 直接在线运行
打开 FigCode 在线绘图,点击本工具卡片的"在线绘图"按钮即可用内置示例数据出图,零环境配置。
2. 本地复现
下载脚本和示例数据,本地 RStudio 运行:
# 下载
curl -O https://<your-site>/figcode/scripts/gsea-forest.R
curl -O https://<your-site>/figcode/data/gsea-forest.csv
3. 安装依赖
# CRAN 包
install.packages(c("ggplot2"))
# Bioconductor 包(如需)
# BiocManager::install(c())
完整代码
library(ggplot2)
# --- Demo data ---
set.seed(42)
gsea_top <- data.frame(
Description = c("Oxidative phosphorylation", "Cell cycle", "DNA repair",
"Fatty acid metabolism", "mTOR signaling",
"Immune activation", "Wnt signaling", "Notch signaling",
"TGF-beta signaling", "p53 pathway"),
NES = c(2.1, 1.8, 1.5, 1.3, 1.1, -1.2, -1.5, -1.7, -2.0, -2.3),
p.adjust = runif(10, 0.001, 0.04),
setSize = sample(20:150, 10)
)
gsea_top$direction <- ifelse(gsea_top$NES > 0, "Activated", "Suppressed")
# --- Plot ---
ggplot(gsea_top, aes(x = NES, y = reorder(Description, NES))) +
geom_point(aes(size = setSize, color = direction)) +
geom_errorbarh(aes(xmin = NES - 0.3, xmax = NES + 0.3), height = 0.2, color = "grey50") +
geom_vline(xintercept = 0, linetype = "dashed") +
scale_color_manual(values = c(Activated="#dc2626", Suppressed="#2563eb")) +
scale_size_continuous(range = c(3, 8)) +
labs(x = "Normalized Enrichment Score", y = NULL, title = "GSEA Forest Plot",
size = "Set Size", color = "Direction") +
theme_classic()
替换为自己的数据
脚本中以 # --- Demo data --- 标注的段落是示例数据生成代码。替换为自己的数据时,保持列名一致即可:
- 输入格式:GSEA 结果表(NES, pvalue, Description, setSize)
- 使用
read.csv()/readRDS()读取本地文件
延伸阅读
- 相关教程:GSEA 森林图 完整流程
- 出现 bug?欢迎在 FigCode 页面 点击对应卡片,在评论区留言。