1. 火山图?

之前瞥到了小明的 跟着Cell学作图:R语言ggplot2作图展示差异表达的基因,但没有细看,根据印象做了下面这个图。

  • 差异表达结果合并
  1. awk 'NR==1{print}FNR>1{print}' *vs0.txt > allvs0.txt
  • 在 R 中读取
  1. library(tidyverse)
  2. df_deg <- read_tsv("allvs0.txt")
  • 作图,其中
    不显示padj大于0.5的基因;
    df_degcontrast 列:1vs0 | 2vs0 | 3vs0 | 4vs0 | 5vs0,不同的组的差异表达结果;
    df_degchange列:Up | Down | Stable,可根据log2FoldChangepadj定义;
    my_gene 是我想突出的基因构成的向量。
  1. ggplot(filter(df_deg, padj <= 0.05 & !geneids %in% my_genes)) +
  2. geom_point(aes(contrast, log2FoldChange, color = change, size = -log10(padj), alpha = -log10(padj)),
  3. # size = 3,
  4. position = "jitter") +
  5. geom_point(data = filter(df_deg, (log2FoldChange >= 1 | log2FoldChange <= -1) & padj <= 0.05 & geneids %in% my_genes),
  6. aes(contrast, log2FoldChange), # size = -log10(padj)
  7. position = "jitter",
  8. size = 4,
  9. shape = 21,
  10. color = "black",
  11. fill = "#fee08b") +
  12. # ylim(-15, 15) +
  13. geom_hline(yintercept = c(-1, 1),
  14. linetype = 'dotdash',
  15. color = 'grey30') +
  16. scale_color_manual(values = c(Up = "#e6550d", Down = "#3182bd", Stable = "#636363")) +
  17. scale_alpha(range = c(0.3, 1)) +
  18. labs(x = 'Group', y = 'Log2(fold change)') +
  19. theme_bw()

火山图绘制 - 图1

2. 常规火山图

  • 只选择一个差异表达结果
  1. library(tidyverse)
  2. library(ggrepel)
  3. df_deg <- read_tsv("1vs0.txt")
  4. ggplot(df_deg) +
  5. geom_point(aes(log2FoldChange, -log10(padj), color = change),
  6. show.legend = F) +
  7. geom_point(data = filter(df_deg, (log2FoldChange >= 1 | log2FoldChange <= -1) & padj <= 0.05 & geneids %in% my_genes),
  8. aes(log2FoldChange, -log10(padj)),
  9. # shape = 21,
  10. # fill = "black",
  11. color = "#fee08b") +
  12. geom_text_repel(data = filter(df_deg, (log2FoldChange >= 1 | log2FoldChange <= -1) & padj <= 0.05 & geneids %in% my_genes),
  13. aes(log2FoldChange, -log10(padj)),
  14. label = "^-^",
  15. box.padding = 0.5,
  16. max.overlaps = Inf) +
  17. scale_color_manual(values = c(Up = "#e6550d", Down = "#3182bd", Stable = "#636363")) +
  18. geom_hline(yintercept = -log10(0.05),
  19. linetype = 'dotdash',
  20. color = 'grey30') +
  21. geom_vline(xintercept = c(-1, 1),
  22. linetype = 'dotdash',
  23. color = 'grey30') +
  24. labs(x = 'Log2(fold change)', y = '-log10(p-value)') +
  25. xlim(-10, 10) +
  26. ylim(0, 30) +
  27. theme_bw()

火山图绘制 - 图2

3. 倾斜火山图

  • 这个啊,应该叫做【热狗图】。

公众号 | 生信宝典 | 什么是倾斜45度的火山图?
简书 | 小明的数据分析笔记本 | 跟着Nature Plants学作图:R语言ggplot2画变种火山图