ggplot2-火山圖

讀取數(shù)據(jù)

## ----------------------------------------------------------------
library(readxl)
de_result <- read_excel("data/vocano/de_result.xlsx", 
    col_types = c("numeric", "text", "text", 
        "text", "text", "numeric", "numeric", 
        "numeric", "numeric", "text", "text", 
        "text", "text", "text", "text", "text", 
        "text", "text"))
library(tidyverse)
selected_genes <- c('FMP27', 'ERG251', 'C5_04050W',
                    'C7_02530C', 'NOT5', 'C6_03800C',
                    'PMC1', 'FEN1', 'ERG3', 'FEN12',
                    'ERG25', 'ERG6', 'MVB12', 'FGR32',
                    'ERG28', 'ERG27')
my_de_result <- select(de_result, GENE_NAME, log2FoldChange, padj) %>%
  mutate(padj = replace_na(padj, 1)) %>%
  mutate(direction = if_else(padj > 0.05 | abs(log2FoldChange) < 1, 
                             'non-significant', 
                             if_else(log2FoldChange >= 1, 
                                     'up-regulated', 
                                     'down-regulated'))) %>%
  mutate(selected = if_else(GENE_NAME %in% selected_genes, 
                            'Yes', direction))

先畫個基本的

library(ggplot2)
library(cowplot)
ggplot(data = my_de_result, aes(x = log2FoldChange, 
                                y = -log10(padj))) +
  geom_point(size = 4,
             aes(color = direction),
             show.legend = F) +
  scale_color_manual(
    values = c('#1500FF', '#A9A9A9', '#FF0102')) +
  ylim(0, 50) +
  labs(x = 'Log2(fold change)', y = '-log10(p-value)') +
  theme_half_open()
Rplot.png

添加上閾值線

library(ggplot2)
library(cowplot)
library(ggrepel)
ggplot(data = my_de_result, aes(x = log2FoldChange, 
                                y = -log10(padj))) +
  geom_point(size = 4,
             aes(color = direction),
             show.legend = F) +
  geom_hline(yintercept = -log10(0.05),  # Y軸位置
             linetype = 'dotdash', # 線型
             color = 'grey30') + # 顏色
  geom_vline(xintercept = c(-1, 1), 
             linetype = 'dotdash', color = 'grey30') +
  scale_color_manual(
    values = c('#1500FF', '#A9A9A9', '#FF0102')) +
  ylim(0, 50) +
  labs(x = 'Log2(fold change)', 
       y = '-log10(p-value)') +
  theme_half_open()
Rplot01.png

給感興趣的基因加上標(biāo)簽

library(ggrepel)
ggplot(data = my_de_result, aes(x = log2FoldChange, 
                                y = -log10(padj))) +
  geom_point(size = 4,
             aes(color = direction),
             show.legend = F) +
  geom_text_repel(data = filter(my_de_result, 
                                selected == 'Yes'),
                  size = 5, box.padding = 0.5,
                  aes(label = GENE_NAME)) +
  geom_hline(yintercept = -log10(0.05), 
             linetype = 'dotdash', color = 'grey30') +
  geom_vline(xintercept = c(-1, 1), 
             linetype = 'dotdash', color = 'grey30') +
  scale_color_manual(values = c('#1500FF', '#A9A9A9', '#FF0102')) +
  ylim(0, 50) +
  labs(x = 'Log2(fold change)', y = '-log10(p-value)') +
  theme_half_open()
Rplot02.png

基因課網(wǎng)址https://genek-pc.duanshu.com/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容