Search code examples
rchartsr-gridvenn-diagram

Placing two venn diagrams on one chart


Using VennDiagram package I'm generating two graphs in the following manner:

# First graph
VennDiagram::draw.pairwise.venn(
    area1 = 100,
    area2 = 70,
    cross.area = 30,
    category = c("A1", "B1"),
    fill = c("#00204DFF", "#FFEA46FF")
) -> vg1

# Second graph
VennDiagram::draw.pairwise.venn(
    area1 = 120,
    area2 = 80,
    cross.area = 10,
    category = c("A2", "B2"),
    fill = c("#000004FF", "#FCFFA4FF")
) -> vg2

When called via grid::grid.draw(vg1) and grid::grid.draw(vg2) the charts show as expected:

grid::grid.draw(vg1) vg1

grid::grid.draw(vg2) vg2

Question

How can I create one grid object where both plots are placed one under another?

Attempt

grdFrme <- grid::grid.frame(name = "gf")
grid::grid.pack("gf", vg1)

Error in packGrob(grid.get(gPath), grob, side, row, row.before, row.after, : invalid 'grob'

Desired results

both graphs


Solution

  • One solution could be to use awesome multipanelfigure package (fill the panels with base, 'lattice', 'ggplot2' and 'ComplexHeatmap' plots, grobs, and PNG, JPEG, SVG and TIFF images).

    library(multipanelfigure)
    figure <- multi_panel_figure(columns = 1, rows = 2)
    
    figure %<>% 
        fill_panel(vg1) %<>%
        fill_panel(vg2)
    

    enter image description here