BioF3 FigCode · SCI 绘图代码集

离散度图(Dispersion Plot)

导出日期:2026年6月27日

分类:差异分析 | 依赖包:ggplot2

解决的生物学问题

基因的离散度估计是否合理?低表达基因的变异是否被适当收缩?

应用场景

输入数据格式

DESeqDataSet 对象(已运行 DESeq())

关键参数

快速开始

1. 直接在线运行

打开 FigCode 在线绘图,点击本工具卡片的"在线绘图"按钮即可用内置示例数据出图,零环境配置。

2. 本地复现

下载脚本和示例数据,本地 RStudio 运行:

# 下载
curl -O https://<your-site>/figcode/scripts/dispersion.R
curl -O https://<your-site>/figcode/data/dispersion.csv

3. 安装依赖

# CRAN 包
install.packages(c("ggplot2"))

# Bioconductor 包(如需)
# BiocManager::install(c())

完整代码

library(ggplot2)

# --- Demo: simulate dispersion estimates ---
set.seed(42)
n <- 2000
baseMean <- 10^runif(n, 0, 4)
# Gene-wise dispersion (noisy)
disp_gene <- 0.5 / sqrt(baseMean) + rnorm(n, 0, 0.1)
disp_gene[disp_gene < 0.001] <- 0.001
# Fitted trend
disp_fitted <- 0.5 / sqrt(baseMean)
# Final (shrunk toward fitted)
disp_final <- disp_gene * 0.3 + disp_fitted * 0.7

df <- data.frame(baseMean = baseMean, gene = disp_gene, fitted = disp_fitted, final = disp_final)

# --- Plot ---
ggplot(df, aes(x = baseMean)) +
  geom_point(aes(y = gene), color = "#9ca3af", size = 0.3, alpha = 0.5) +
  geom_point(aes(y = final), color = "#2563eb", size = 0.3, alpha = 0.5) +
  geom_line(aes(y = fitted), color = "#dc2626", linewidth = 1) +
  scale_x_log10() + scale_y_log10() +
  labs(x = "Mean of normalized counts", y = "Dispersion",
       title = "Dispersion Estimates") +
  annotate("text", x = 1000, y = 2, label = "gene-wise", color = "#9ca3af", size = 3) +
  annotate("text", x = 1000, y = 0.5, label = "final", color = "#2563eb", size = 3) +
  annotate("text", x = 1000, y = 0.1, label = "fitted", color = "#dc2626", size = 3) +
  theme_classic()

替换为自己的数据

脚本中以 # --- Demo data --- 标注的段落是示例数据生成代码。替换为自己的数据时,保持列名一致即可:

延伸阅读