Search code examples
rvenn-diagram

How to put many vennplots in one slide/plot


I have five venndigram plots and I want put them in one slide. I wonder anyone could help me how to do it. I used the the following code but could not help me.

gridExtra::grid.arrange(grobs = list(VD1, VD2, VD3, VD4, VD5),
                        ncol = 3, nrow = 2, labels = LETTERS[1:5])

These were the errors

Error in gList(list(1, wrapvp = list(x = 0.5, y = 0.5, width = 1, height = 1,  : 
only 'grobs' allowed in "gList"
In addition: Warning messages:
 1: In grob$wrapvp <- vp : Coercing LHS to a list
 2: In grob$wrapvp <- vp : Coercing LHS to a list
 3: In grob$wrapvp <- vp : Coercing LHS to a list
 4: In grob$wrapvp <- vp : Coercing LHS to a list
 5: In grob$wrapvp <- vp : Coercing LHS to a list

Thank you!


Solution

  • You can use grid.arrange in combination with gTree like this:

    library(VennDiagram)
    #> Loading required package: grid
    #> Loading required package: futile.logger
    library(gridExtra)
    set.seed(1)
    list1 <- list(A=sample(LETTERS, 12), B=sample(LETTERS, 12))
    venn1 <- venn.diagram(list1, filename = NULL)
    set.seed(2)
    list2 <- list(A=sample(LETTERS, 16), B=sample(LETTERS, 12))
    venn2 <- venn.diagram(list2, filename = NULL)
    
    venn3 <- venn.diagram(list(C=sample(LETTERS, 16), D=sample(LETTERS, 12)), filename = NULL)
    venn4 <- venn.diagram(list(E=sample(LETTERS, 20), F=sample(LETTERS, 22)), filename = NULL)
    venn5 <- venn.diagram(list(G=sample(LETTERS, 13), H=sample(LETTERS, 14)), filename = NULL)
    grid.arrange(gTree(children=venn1),
                 gTree(children=venn2),
                 gTree(children=venn3),
                 gTree(children=venn4),
                 gTree(children=venn5),
                 ncol=3)
    

    Created on 2020-07-21 by the reprex package (v0.3.0)(https://reprex.tidyverse.org) (v0.3.0)