美文网首页TCGA作图绘图技巧
R语言绘图包03--火山图EnhancedVolcano

R语言绘图包03--火山图EnhancedVolcano

作者: Hayley笔记 | 来源:发表于2021-06-14 15:12 被阅读0次

    R语言绘图包系列:


    1. 介绍

    火山图(Volcano plot)用于展示基因表达差异的分布,横轴为LogFC(Log2 Fold Change,Fold Chang是处理组平均值/对照组平均值),越偏离中心表示差异倍数越大;纵轴为-Log10(P.Value),值越大差异越显著。一般横轴越偏离中心的点其纵轴值也会比较大,因此呈现火山喷发的形状。(火山图其实就是一种特殊的点图)

    2. 安装

    if (!requireNamespace('BiocManager', quietly = TRUE))
        install.packages('BiocManager')
    BiocManager::install('EnhancedVolcano')
    # to install development version:
    # devtools::install_github('kevinblighe/EnhancedVolcano')
    library(EnhancedVolcano)
    

    3. 绘图

    数据准备

    library(airway)
    library(magrittr)
    data('airway')
    airway$dex %<>% relevel('untrt')
    

    根据gene symbols添加Ensembl IDs

    ens <- rownames(airway)
    
    library(org.Hs.eg.db)
    symbols <- mapIds(org.Hs.eg.db, keys = ens,
                      column = c('SYMBOL'), keytype = 'ENSEMBL')
    symbols <- symbols[!is.na(symbols)]
    symbols <- symbols[match(rownames(airway), names(symbols))]
    rownames(airway) <- symbols
    keep <- !is.na(rownames(airway))
    airway <- airway[keep,]
    

    使用Deseq2进行差异分析

    library('DESeq2')
    
    dds <- DESeqDataSet(airway, design = ~ cell + dex)
    dds <- DESeq(dds, betaPrior=FALSE)
    res <- results(dds,
                   contrast = c('dex','trt','untrt'))
    res <- lfcShrink(dds,
                     contrast = c('dex','trt','untrt'), res=res, type = 'normal')
    
    3.1 绘制最基本的火山图
    EnhancedVolcano(res,
                    lab = rownames(res),
                    x = 'log2FoldChange',
                    y = 'pvalue')
    

    4. 绘图细节调整

    4.1 调整log2FC和P值的cutoffs,设置图片标题,调整点和标签的大小
    EnhancedVolcano(res,
                      lab = rownames(res),
                      x = 'log2FoldChange',
                      y = 'pvalue',
                      title = 'N061011 versus N61311',
                      pCutoff = 10e-32,
                      FCcutoff = 0.5,
                      pointSize = 3.0,
                      labSize = 6.0)
    
    4.2 调整点的颜色和透明度
    EnhancedVolcano(res,
                    lab = rownames(res),
                    x = 'log2FoldChange',
                    y = 'pvalue',
                    title = 'N061011 versus N61311',
                    pCutoff = 10e-16,
                    FCcutoff = 1.5,
                    pointSize = 3.0,
                    labSize = 6.0,
                    col=c('black', 'black', 'black', 'red3'),
                    colAlpha = 1)
    
    4.3 调整点的形状
    EnhancedVolcano(res,
                    lab = rownames(res),
                    x = 'log2FoldChange',
                    y = 'pvalue',
                    title = 'N061011 versus N61311',
                    pCutoff = 10e-16,
                    FCcutoff = 1.5,
                    pointSize = 4.0,
                    labSize = 6.0,
                    shape = 8,
                    colAlpha = 1)
    
    EnhancedVolcano(res,
                    lab = rownames(res),
                    x = 'log2FoldChange',
                    y = 'pvalue',
                    title = 'N061011 versus N61311',
                    pCutoff = 10e-16,
                    FCcutoff = 1.5,
                    pointSize = 3.0,
                    labSize = 6.0,
                    shape = c(1, 4, 23, 25),
                    colAlpha = 1)
    
    4.4 调整p值的cutoff
    EnhancedVolcano(res,
                    lab = rownames(res),
                    x = 'log2FoldChange',
                    y = 'pvalue',
                    xlim = c(-6, 6),
                    title = 'N061011 versus N61311',
                    subtitle = paste0('p-value cutoff (red line) drawn ',
                                      'at equivalent of adjusted p=0.0001'),
                    pCutoff = 0.0001,
                    FCcutoff = 1.5,
                    pointSize = 3.0,
                    labSize = 6.0,
                    colAlpha = 1,
                    cutoffLineType = 'solid',
                    cutoffLineCol = 'red2',
                    cutoffLineWidth = 2.5,
                    hline = c(10e-20,
                              10e-20 * 10e-30,
                              10e-20 * 10e-60,
                              10e-20 * 10e-90),
                    hlineCol = c('black', 'black', 'black', 'black'),
                    hlineType = c('longdash', 'longdash', 'dotdash', 'dotdash'),
                    hlineWidth = c(0.4, 0.4, 0.8, 0.8),
                    gridlines.major = FALSE,
                    gridlines.minor = FALSE)
    
    4.5 调整图例位置大小和文字
    EnhancedVolcano(res,
                    lab = rownames(res),
                    x = 'log2FoldChange',
                    y = 'pvalue',
                    pCutoff = 10e-12,
                    FCcutoff = 1.5,
                    cutoffLineType = 'twodash',
                    cutoffLineWidth = 0.8,
                    pointSize = 4.0,
                    labSize = 6.0,
                    colAlpha = 1,
                    legendLabels=c('Not sig.','Log (base 2) FC','p-value',
                                   'p-value & Log (base 2) FC'),
                    legendPosition = 'right',
                    legendLabSize = 16,
                    legendIconSize = 5.0)
    

    不显示图例

    legendPosition = 'none'
    
    4.6 通过添加connectors来加入更多标签
    EnhancedVolcano(res,
                    lab = rownames(res),
                    x = 'log2FoldChange',
                    y = 'pvalue',
                    xlab = bquote(~Log[2]~ 'fold change'),
                    pCutoff = 10e-32,
                    FCcutoff = 2.0,
                    pointSize = 4.0,
                    labSize = 6.0,
                    colAlpha = 1,
                    legendPosition = 'right',
                    legendLabSize = 12,
                    legendIconSize = 4.0,
                    drawConnectors = TRUE,
                    widthConnectors = 0.75)
    
    4.7 仅对重要变量添加注释
    EnhancedVolcano(res,
                    lab = rownames(res),
                    x = 'log2FoldChange',
                    y = 'pvalue',
                    selectLab = c('TMEM176B','ADH1A'),
                    xlab = bquote(~Log[2]~ 'fold change'),
                    pCutoff = 10e-14,
                    FCcutoff = 2.0,
                    pointSize = 4.0,
                    labSize = 6.0,
                    shape = c(4, 35, 17, 18),
                    colAlpha = 1,
                    legendPosition = 'right',
                    legendLabSize = 14,
                    legendIconSize = 5.0)
    
    4.8 添加盒型注释
    EnhancedVolcano(res,
                    lab = rownames(res),
                    x = 'log2FoldChange',
                    y = 'pvalue',
                    selectLab = c('VCAM1','KCTD12','ADAM12',
                                  'CXCL12','CACNB2','SPARCL1','DUSP1','SAMHD1','MAOA'),
                    xlab = bquote(~Log[2]~ 'fold change'),
                    pCutoff = 10e-14,
                    FCcutoff = 2.0,
                    pointSize = 4.0,
                    labSize = 6.0,
                    labCol = 'black',
                    labFace = 'bold',
                    boxedLabels = TRUE,
                    colAlpha = 4/5,
                    legendPosition = 'right',
                    legendLabSize = 14,
                    legendIconSize = 4.0,
                    drawConnectors = TRUE,
                    widthConnectors = 1.0,
                    colConnectors = 'black')
    
    4.9 添加斜体标签,转置火山图
    lab_italics <- paste0("italic('", rownames(res), "')")
    selectLab_italics = paste0(
        "italic('",
        c('VCAM1','KCTD12','ADAM12', 'CXCL12','CACNB2','SPARCL1','DUSP1','SAMHD1','MAOA'),
        "')")
    
    EnhancedVolcano(res,
                    lab = lab_italics,
                    x = 'log2FoldChange',
                    y = 'pvalue',
                    selectLab = selectLab_italics,
                    xlab = bquote(~Log[2]~ 'fold change'),
                    pCutoff = 10e-14,
                    FCcutoff = 1.0,
                    pointSize = 3.0,
                    labSize = 6.0,
                    labCol = 'black',
                    labFace = 'bold',
                    boxedLabels = TRUE,
                    col = c('black', 'pink', 'purple', 'red3'),
                    colAlpha = 4/5,
                    legendPosition = 'bottom',
                    legendLabSize = 14,
                    legendIconSize = 4.0,
                    drawConnectors = TRUE,
                    widthConnectors = 1.0,
                    colConnectors = 'black') + coord_flip()
    

    参考:
    http://www.bioconductor.org/packages/release/bioc/vignettes/EnhancedVolcano/inst/doc/EnhancedVolcano.html

    相关文章

      网友评论

        本文标题:R语言绘图包03--火山图EnhancedVolcano

        本文链接:https://www.haomeiwen.com/subject/mafneltx.html