Combining multiple complex plots as panels in a single figure

前端 未结 4 1677
北荒
北荒 2020-12-05 10:59

Introduction by @backlin

Multiple simple plots can combined as panels in a single figure by using layout or par(mfrow=...). However, more

4条回答
  •  误落风尘
    2020-12-05 11:17

    I struggled with a similar problem and came up with a solution that is very easy but requires imagemagick installed. The idea is to plot the heatmaps to separate files and then combine them with the montage command:

    library(gplots)
    row.scaled.expr <- matrix(sample(1:10000),nrow=1000,ncol=10)
    arr <- array(data=row.scaled.expr, dim=c(dim(row.scaled.expr),4))
    par(mfrow=c(2,2))
    for (i in 1:4) {
        ifile <- paste0(i,'_heatmap.pdf')
        pdf(ifile)
        heatmap.2(arr[ , ,i], dendrogram ='row',
                            Colv=FALSE, col=greenred(800), 
                            key=FALSE, keysize=1.0, symkey=FALSE, density.info='none',
                            trace='none', colsep=1:10,
                            sepcolor='white', sepwidth=0.05,
                            scale="none",cexRow=0.2,cexCol=2,
                            labCol = colnames(arr[ , ,i]),                 
                            hclustfun=function(c){hclust(c, method='mcquitty')},
                            lmat=rbind( c(0, 3), c(2,1), c(0,4) ), lhei=c(0.25, 4, 0.25 ),                 
        )
        dev.off()
    }
    system('montage -geometry 100% -tile 2x2 ./*_heatmap.pdf outfile.pdf')
    

提交回复
热议问题