BioF3 FigCode · SCI 绘图代码集

富集气泡图(GO/KEGG Dotplot)

导出日期:2026年6月27日

分类:功能富集 | 依赖包:ggplot2

解决的生物学问题

差异基因主要富集在哪些生物学通路或功能类别中?

应用场景

输入数据格式

enrichGO / enrichKEGG 结果对象

关键参数

快速开始

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 --- 标注的段落是示例数据生成代码。替换为自己的数据时,保持列名一致即可:

延伸阅读