volcano

作者: 天道昭然 | 来源:发表于2020-02-28 15:20 被阅读0次
    library(ggplot2)
    
    ##一个展示基因差异表达水平的火山图示例
    gene =allDiff
    
    #例如这里自定义根据 |log2FC| >= 1 和 adj.P.Val < 0.01 标记差异类型
    gene[which(gene$FDR < 0.01 & gene$logFC <= -1),'sig'] <- 'Down'
    gene[which(gene$FDR < 0.01 & gene$logFC >= 1),'sig'] <- 'Up'
    gene[which(gene$FDR >= 0.01 | abs(gene$logFC) < 1),'sig'] <- 'None'
    
    #横轴 log2FC,纵轴 -log10(adj.P.Val),颜色表示差异
    p <- ggplot(gene, aes(x = logFC, y = -log10(FDR), color = sig)) +
      geom_point(alpha = 0.6, size = 1) +
      scale_colour_manual(values  = c('red2', 'blue2', 'gray'), limits = c('Up', 'Down', 'None'))+
      theme(panel.grid = element_blank(), panel.background = element_rect(color = 'black', fill = 'transparent'), plot.title = element_text(hjust = 0.5)) +
      theme(legend.key = element_rect(fill = 'transparent'), legend.background = element_rect(fill = 'transparent'), legend.position = c(0.9, 0.93)) +
      geom_vline(xintercept = c(-1, 1), color = 'gray', size = 0.3) +
      geom_hline(yintercept = -log(0.01, 10), color = 'gray', size = 0.3) +
      xlim(-10, 10) + ylim(0, 20) +
      labs(x = '\nlog2 Fold Change', y = '-log10(FDR)\n', color = '', title = 'LUAD:Cancer vs Normal\n')
    
    p
    
    #ggsave('gene.pdf', p, width = 5, height = 6)
    ggsave('gene.png', p, width = 5, height = 6)
    

    相关文章

      网友评论

          本文标题:volcano

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