BioF3 FigCode · SCI 绘图代码集
Reactome 通路树(Reactome Pathway Tree)
分类:功能富集 | 依赖包:clusterProfiler、enrichplot、org.Hs.eg.db、DOSE
解决的生物学问题
富集到几十条通路,但很多是冗余的——能不能把它们按相似性聚成几大主题?
应用场景
- 富集结果去冗余呈现
- 论文图替代长 dotplot
- GO BP 大量条目时聚类
- 多组对比通路主题对比
输入数据格式
enrichResult 对象(clusterProfiler::enrichGO / enrichKEGG / enrichPathway)
关键参数
- showCategory = 30(参与聚类的 top N)
- nCluster = 4-6(树枝数)
- hclust_method = "ward.D"
- group_color 自定义簇配色
快速开始
1. 直接在线运行
打开 FigCode 在线绘图,点击本工具卡片的"在线绘图"按钮即可用内置示例数据出图,零环境配置。
2. 本地复现
下载脚本和示例数据,本地 RStudio 运行:
# 下载
curl -O https://<your-site>/figcode/scripts/reactome-tree.R
curl -O https://<your-site>/figcode/data/reactome-tree.csv
3. 安装依赖
# CRAN 包
install.packages(c("DOSE"))
# Bioconductor 包(如需)
# BiocManager::install(c("clusterProfiler", "enrichplot", "org.Hs.eg.db"))
完整代码
library(clusterProfiler)
library(enrichplot)
library(org.Hs.eg.db)
# --- Demo: built-in geneList ---
data(geneList, package = "DOSE")
genes <- names(geneList)[abs(geneList) > 2]
ego <- enrichGO(
gene = genes,
OrgDb = org.Hs.eg.db,
ont = "BP",
pAdjustMethod = "BH",
pvalueCutoff = 0.05,
qvalueCutoff = 0.1,
readable = TRUE
)
# --- Tree plot ---
ego2 <- pairwise_termsim(ego)
treeplot(
ego2,
showCategory = 30,
cluster.params = list(label_words_n = 4),
fontsize = 4
) +
ggtitle("Reactome / GO Enrichment Tree")
替换为自己的数据
脚本中以 # --- Demo data --- 标注的段落是示例数据生成代码。替换为自己的数据时,保持列名一致即可:
- 输入格式:enrichResult 对象(clusterProfiler::enrichGO / enrichKEGG / enrichPathway)
- 使用
read.csv()/readRDS()读取本地文件
延伸阅读
- 相关教程:Reactome 通路树 完整流程
- 出现 bug?欢迎在 FigCode 页面 点击对应卡片,在评论区留言。