I am looking to find a way to be able to make such a figure
I need to have Venn diagram for pairwise and I know that I can do each at the time like this
grid.newpage()
draw.pairwise.venn(22, 20, 11, category = c("Dog People", "Cat People"), lty = rep("blank",
2), fill = c("light blue", "pink"), alpha = rep(0.5, 2), cat.pos = c(0,
0), cat.dist = rep(0.025, 2))
Now lets say I have 6 sets as follows, can someone comment?
draw.pairwise.venn(22, 20, 11)
draw.pairwise.venn(33, 55, 5)
draw.pairwise.venn(44, 22, 2)
draw.pairwise.venn(330, 550, 50)
draw.pairwise.venn(2200, 400, 0)
draw.pairwise.venn(25, 33, 0)
CodePudding user response:
You can do this at a fairly low level within the grid
framework by defining the 6 viewports in a list, the arguments for the diagrams in a list, and a function that uses these arguments to draw a diagram in each viewport. Then just Map
them together:
library(grid)
library(VennDiagram)
vps <- lapply(1:6, function(x) viewport(x = 0.75 - (x %% 2)/2,
y = 1/6 ((x - 1) %/% 2)/3,
width = 0.5,
height = 1/3))
venns <- list(c(22, 20, 11),
c(33, 55, 5),
c(44, 22, 2),
c(330, 550, 50),
c(2200, 400, 0),
c(25, 33, 0))
labels <- paste("label", 1:6)
func <- function(vp, venn, lab) {
pushViewport(vp)
draw.pairwise.venn(venn[1], venn[2], venn[3],
category = c("Dog People", "Cat People"),
lty = rep("blank", 2), ext.text = FALSE,
fill = c("light blue", "pink"),
alpha = rep(0.5, 2), cat.pos = c(0, 0),
cat.dist = rep(0.025, 2))
grid.draw(textGrob(lab, 0.8, 0.1, gp = gpar(fontface = 2)))
popViewport()
}
grid.newpage()
Map(func, vp = vps, venn = venns, lab = labels)
Edit
Example with 9 viewports:
vps <- lapply(1:9, function(x) viewport(x = 1/6 ((x - 1) %% 3)/3,
y = 1/6 ((x - 1) %/% 3)/3,
width = 1/3,
height = 1/3))
venns <- list(c(22, 20, 11),
c(33, 55, 5),
c(44, 22, 2),
c(330, 550, 50),
c(2200, 400, 0),
c(25, 33, 0),
c(22, 20, 11),
c(33, 55, 5),
c(44, 22, 2))
labels <- paste("label", 1:9)
grid.newpage()
Map(func, vp = vps, venn = venns, lab = labels)