BioF3 FigCode · SCI 绘图代码集

LFC 对比图(LFC Scatter)

导出日期:2026年6月27日

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

解决的生物学问题

不同差异分析工具得到的 fold change 估计是否一致?哪些基因存在工具间分歧?

应用场景

输入数据格式

数据框:gene, lfc_tool1, lfc_tool2

关键参数

快速开始

1. 直接在线运行

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

2. 本地复现

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

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

3. 安装依赖

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

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

完整代码

library(ggplot2)

# --- Demo data ---
set.seed(42)
n <- 1500
lfc1 <- rnorm(n, 0, 2)
lfc2 <- lfc1 + rnorm(n, 0, 0.5)  # Correlated with noise
compare_df <- data.frame(lfc_deseq2 = lfc1, lfc_edger = lfc2)
cor_val <- cor(lfc1, lfc2)

# --- Plot ---
ggplot(compare_df, aes(x = lfc_deseq2, y = lfc_edger)) +
  geom_point(size = 0.8, alpha = 0.4, color = "#475569") +
  geom_abline(slope = 1, intercept = 0, linetype = "dashed", color = "red") +
  geom_smooth(method = "lm", se = FALSE, color = "#2563eb") +
  annotate("text", x = -4, y = 5, label = paste0("r = ", round(cor_val, 3)),
           size = 4, fontface = "bold") +
  labs(x = "log2FC (DESeq2)", y = "log2FC (edgeR)",
       title = "LFC Concordance: DESeq2 vs edgeR") +
  theme_classic()

替换为自己的数据

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

延伸阅读