BioF3 FigCode · SCI 绘图代码集
富集气泡图(GO/KEGG Dotplot)
分类:功能富集 | 依赖包:ggplot2
解决的生物学问题
差异基因主要富集在哪些生物学通路或功能类别中?
应用场景
- GO 富集结果可视化
- KEGG 通路富集展示
- 多组对比富集结果
- 上下调基因分别富集分析
输入数据格式
enrichGO / enrichKEGG 结果对象
关键参数
- showCategory 展示通路数(10-20)
- pvalueCutoff 阈值
- OrgDb 物种注释库
- ont 本体类型(BP/MF/CC)
- gene ratio vs count 选择
快速开始
1. 直接在线运行
打开 FigCode 在线绘图,点击本工具卡片的"在线绘图"按钮即可用内置示例数据出图,零环境配置。
2. 本地复现
下载脚本和示例数据,本地 RStudio 运行:
# 下载
curl -O https://<your-site>/figcode/scripts/dotplot.R
curl -O https://<your-site>/figcode/data/dotplot.csv
3. 安装依赖
# CRAN 包
install.packages(c("ggplot2"))
# Bioconductor 包(如需)
# BiocManager::install(c())
完整代码
library(ggplot2)
# --- Demo data (simulated enrichment result) ---
set.seed(42)
terms <- c("Cell cycle regulation", "DNA repair", "Apoptosis signaling",
"Immune response", "Metabolic process", "Signal transduction",
"Protein folding", "mRNA processing", "Chromatin remodeling",
"Lipid metabolism", "Oxidative phosphorylation", "Autophagy")
enrich_df <- data.frame(
Description = terms,
GeneRatio = runif(12, 0.05, 0.25),
p.adjust = sort(runif(12, 0.0001, 0.04)),
Count = sample(5:40, 12)
)
# --- Plot ---
ggplot(enrich_df, aes(x = GeneRatio, y = reorder(Description, GeneRatio))) +
geom_point(aes(size = Count, color = p.adjust)) +
scale_color_gradient(low = "#dc2626", high = "#2563eb") +
scale_size_continuous(range = c(3, 10)) +
labs(x = "Gene Ratio", y = NULL, title = "GO Enrichment Dotplot",
color = "p.adjust", size = "Count") +
theme_classic() +
theme(axis.text.y = element_text(size = 10))
替换为自己的数据
脚本中以 # --- Demo data --- 标注的段落是示例数据生成代码。替换为自己的数据时,保持列名一致即可:
- 输入格式:enrichGO / enrichKEGG 结果对象
- 使用
read.csv()/readRDS()读取本地文件
延伸阅读
- 相关教程:富集气泡图 完整流程
- 出现 bug?欢迎在 FigCode 页面 点击对应卡片,在评论区留言。