火山图

作者: 一路向前_莫问前程_前程似锦 | 来源:发表于2018-09-03 18:39 被阅读148次

    画第一张图

    image.png
    library(ggplot2)
    library(ggrepel)
    #library(ggsci)
    library(dplyr)
    #提取数据,resG是注释过基因名字的DEseq2结果
    Vol.TG<-na.omit(resYvsM_order) 
    #给结果加上change,其中padj和log2FoldChange后面的值根据自己的需要修改
    Vol.TG$change <- as.factor(ifelse(Vol.TG$pvalue < 0.05 & abs(Vol.TG$log2FoldChange) > 1,ifelse(Vol.TG$log2FoldChange > 1,'UP','DOWN'),'NOT'))
    #加个配色
    #mypal_V = pal_gsea("default", n = 3, alpha = 0.9)(3)
    #开始设置ggplot
    #其中geom_point中alpha是点的透明度,size是点大小都可以修改。
    #其中xlim是x轴范围,自己根据数据调整
    #theme_bw中base_size是图中文字字号
    #theme中那些事调整格子的,想知道效果删掉一个看一下。
    #scale_color_manual中values后面值是配色,可以用c("","","")自己填颜色代号调整。limits代表change的顺序,这个要配合颜色顺序调整。
    p <- ggplot(data = Vol.TG, aes(x = log2FoldChange, y = -log10(pvalue), color = change))+geom_point(alpha=0.8, size = 1)+scale_color_manual(values =c("blue","black","red"))+
    geom_hline(yintercept = -log10(0.05),lty=4,lwd=0.6,alpha=0.8)+geom_vline(xintercept = c(1,-1),lty=4,lwd=0.6,alpha=0.8)+xlim(-9,9)+theme_bw(base_size = 18)+theme(panel.grid.minor = element_blank(),panel.grid.major = element_blank())
    #输出p
    p
    #加上基因名,其中padj和log2FoldChange后面的值根据自己的需要修改
    p+geom_text_repel(data=subset(data, abs(log2FoldChange) > 4.5), aes(label=row),col="black",alpha = 0.8)
    

    画第二张图

    image.png
    ##try drowing a volcano by gglot2
    library(ggplot2)
    library(ggrepel)
    library(dplyr)
    data <- resYvsM_order
    data$significant <- as.factor(data$pvalue <0.05 & abs(data$log2FoldChange) > 1)
    data$gene <- rownames(data)
    ggplot(data=data, aes(x=log2FoldChange, y =-log10(pvalue),color=significant)) +
      geom_point(alpha=0.8, size=1.2)+
      scale_color_manual(values =c("black","red"))+
      labs(title="Volcanoplot", x="log2 (fold change)",y="-log10 (q-value)")+
      theme(plot.title = element_text(hjust = 0.4))+
      geom_hline(yintercept = -log10(0.05),lty=4,lwd=0.6,alpha=0.8)+
      geom_vline(xintercept = c(1,-1),lty=4,lwd=0.6,alpha=0.8)+
      #theme(legend.position='none')
      theme_bw()+
      theme(panel.border = element_blank(),
            panel.grid.major = element_blank(), 
            panel.grid.minor = element_blank(),   
            axis.line = element_line(colour = "black")) +
      #geom_text(aes(x=4,y=5,label="class is over"),col ="black",size = 10)+
      #geom_text(data=subset(data, abs(logFC) > 3), aes(label=gene),col="green",alpha = 0.5)
      geom_text_repel(data=subset(data, abs(log2FoldChange) > 8), aes(label=gene),col="black",alpha = 0.8)
    #ggsave("vocanol.pdf",,width = 7.09, height =5.6,dpi = 300)
    

    相关文章

      网友评论

        本文标题:火山图

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