Venn diagrams in several figures

is there a way to have the following venn diagrams as the 3rd drawing after the two histograms below? I would like two venn diagrams one on top of the other

library(VennDiagram)

plus.venn<-draw.pairwise.venn(368, 1171, 149) #venn diagram 1

minus.venn<-draw.pairwise.venn(349, 1335, 173) #venn diagram 2

par(mfrow=c(1,3))

a<-sample(1:10000,3000)

b<-sample(5000:15000,3000)

hist(a)

hist(b)
+3
source share
1 answer

Turn around to MrFlicks and my comments above.

You can combine basic and grid graphics with the package gridBase. However, if you are not limited in the use of basic R graphics, it may be easier for you to create all your graphics with a grid-based graphics package and combine them with the package gridExtra.

Your data

library(VennDiagram)

plus.venn <- draw.pairwise.venn(368, 1171, 149) #venn diagram 1
minus.venn <-draw.pairwise.venn(349, 1335, 173) #venn diagram 2
a <-sample(1:10000,3000)
b <-sample(5000:15000,3000)

Placing basic and grid charts

library(grid)
library(gridBase)

# Layout of plots - 4 plots of equal size
layout(matrix(1:4, 2, byrow = TRUE))

# First & second base plot
hist(a)
hist(b)

# Grid regions of current base plot (ie from frame)
frame()
vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)
grid.draw(plus.venn)
popViewport(3)

# fourth
frame()
vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)  
grid.draw(minus.venn)
popViewport(3)

What produces

enter image description here

ggplot2 grid.arrange

library(ggplot2)
library(gridExtra)

grid.arrange(qplot(a, geom="histogram") + theme_classic(),
             qplot(b, geom="histogram") + theme_classic(),
             grobTree(plus.venn),
             grobTree(minus.venn),
             ncol=2)

enter image description here

, .

+6

Source: https://habr.com/ru/post/1661805/


All Articles