Placing two venn diagrams on one chart
Asked Answered
L

1

6

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

Leaguer answered 28/5, 2018 at 17:13 Comment(1)
I believe this is also pretty easy with the gridExtra package. At one point, I figured out how to do this in grid itself, but it's kind of a pain.Tarango
B
4

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

Botha answered 28/5, 2018 at 17:38 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.