美文网首页R 绘图
组合Venn图和Heatmap图

组合Venn图和Heatmap图

作者: 水跃君的叹息 | 来源:发表于2019-01-10 16:05 被阅读0次

    处理数据list

    library(VennDiagram)
    
    #导入数据,下调数据
    1d <- read.table("...diff/1_DEseq2.DEG_down.xls", sep='\t', header=T)
    2d <- read.table("...diff/2_DEseq2.DEG_down.xls", sep='\t', header=T)
    3d <- read.table("...diff/3_DEseq2.DEG_down.xls", sep='\t', header=T)
    4d <- read.table("...diff/4_DEseq2.DEG_down.xls", sep='\t', header=T)
    

    类似地,导入 #上调数据 #全部数据

    然后可以做成表,写出数据后分别查看1U2,1U2U3集合内容

    #做成表
    input_down  <-list(1d$gene_id,2d$gene_id,3d$gene_id,4d$gene_id)
    Table_down<-calculate.overlap(input_down)
    
    input_up  <-list(1d$gene_id,2d$gene_id,3d$gene_id,4d$gene_id)
    Table_up<-calculate.overlap(input_up)
    
    #写出投加共同上调or下调的表格
    write.table(Table_down$“你需要的组合”, file = "mutually down-DESeq2.csv", sep = ",", col.names = NA,qmethod = "double")
    

    绘制Venn图

    #绘制Venn图
    up<-venn.diagram(input_up,NULL, main.cex = 2,
                category = c("1d", "2d", "3d","4d"),fill = c("dodgerblue", "green", "orange", "darkorchid4"),
                alpha=0.3, cex=1.5, cat.fontface=2, cat.cex = 1, cat.col= c("dodgerblue", "green", "orange", "darkorchid4"),   imagetype = "tiff", ext.line.lty = "dotted", lty = "dotted",
                ext.line.lwd = 0.5,force.unique = F, lwd = 1, main.fontfamily="serif", main = "Up-regulated") #, filename = "Vennup.tif"
    
    down<-venn.diagram(input_down,main.cex = 2,
                category = c("1d", "2d", "3d","4d"),fill = c("dodgerblue", "green", "orange", "darkorchid4"),
                alpha=0.3, cex=1.5, cat.fontface=2, cat.cex = 1, cat.col= c("dodgerblue", "green", "orange", "darkorchid4"), imagetype = "tiff", ext.line.lty = "dotted", lty = "dotted",
                ext.line.lwd = 0.5,force.unique = F, lwd = 1, main.fontfamily="serif", main = "Down-regulated", filename = "Venndown.tif")
    

    分别得到一张上调Venn图和一张下调Venn图,用grid.draw()命令可以查看效果

    使用pheatmap绘制heatmap

    library(pheatmap)
    x<-read.table("Union_for_cluster.xls", sep = "\t", header=T, row.names = 1)
    
    x<-pheatmap(x, clustering_distance_rows = "euclidean", clustering_distance_cols = "euclidean"
            ,annotation_row = NA, cellwidth = 15,show_rownames = F, drop_levels = F
            ,clustering_method = "average", scale = "row")
    
    #the agglomeration method should be one of "ward.D", "ward.D2", "single","complete", "average" (= UPGMA), "mcquitty" (= WPGMA), "median" (= WPGMC) or "centroid" (= UPGMC).
    

    把两张Venn图和一张heatmap图组合在一起

    这件事费了我好大功夫啊……本来想看看Y叔有什么神奇的办法,因为自己是个半吊子,但是看了听说你还不会画heatmap以后也没学会,Y叔说可以用cowplot包,plot_grid这个函数可以拼一切基于grid的图。pheatmap是可以,但是VennDiagram生成对象是gList,用plot_grid()这个命令没办法处理gList,不停报错(差点掀桌),没办法,只好自己慢慢啃呲(谁让我是半瓶水呢)。

    grid.newpage()
    pushViewport(plotViewport(layout=grid.layout(2, 2,just = "centre")))
    pushViewport(plotViewport(layout.pos.row=1, layout.pos.col=1))
    grid.draw(up)
    popViewport()
    pushViewport(plotViewport(layout.pos.row=2, layout.pos.col=1, clip="on"))
    grid.draw(down)
    popViewport()
    pushViewport(plotViewport(layout.pos.col=2, clip="inherit"))
    grid.draw(x$gtable)
    popViewport()
    
    image.png

    好了,因为用了自己的数据所以只能传一张高糊图片,总之最终效果就是左边2张Venn右边1张heatmap

    相关文章

      网友评论

        本文标题:组合Venn图和Heatmap图

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