Search code examples
rpar

R: is it possible to have multiple EnhancedVolcano plots in a single graph?


I tried to put multiple EnhancedVolcano plots in a single image, but par(mfrow) had no effect.

I tried, for example, the following codes, but the image created had only the last plot. I have RedHat 8 with R 4.2.2 and EnhancedVolcano 1.16.0. Thanks.

png("volcano.png", width=480*2)
par(mfrow=c(1,2))
EnhancedVolcano(res,
        lab = rownames(res),
        x = 'log2FoldChange',
        y = 'pvalue')

EnhancedVolcano(res,
        lab = rownames(res),
        x = 'log2FoldChange',
        y = 'padj')

dev.off()

Solution

  • The package gridExtra gives me a solution, as shown in the following example.

    library(gridExtra)
    library(grid)
    library("EnhancedVolcano")
    
    p1 <- EnhancedVolcano(res,
            lab = rownames(res),
            x = 'log2FoldChange',
            y = 'pvalue')
    
    p2 <- EnhancedVolcano(res,
            lab = rownames(res),
            x = 'log2FoldChange',
            y = 'padj')
    
    grid.arrange(p1, p2, ncol=2)