12
votes

What would be the easiest way to redraw a venn diagram using R ? I do not have a data which was used to generate venn diagram but the rest of diagrams were drawn in R... I would like to keep the same structure so it means I have to somehow redraw it in R.

Do you have any idea what would be the easiest way to do it ? That is venn diagram I have to create in R

That's a code which I have been using for other venn diagrams.

v1 <- venn.diagram(list(1=a, 2=b, 3=c, 4=d), filename=NULL, fill=rainbow(4), cex.prop=NULL, cex=1.5)
png("TEST.png", width=7, height=7, units='in', res=150)
grid.newpage()
grid.draw(v1)
dev.off()
2

2 Answers

10
votes

You can make a call to the draw.venn.* functions and input overlap areas directly. It will be tedious but i think it is your only option. you'll notice the order of groups is different, there maybe a way to control that but I'm not sure what that is at the moment.

a <- c(2411, 12433,939,238, 1575,2483,2923,540)
b <- c(1575, 2483,2923, 540, 1255, 1330, 615, 622)
c <- c(1247, 1330, 2483, 12433, 150, 615, 2923, 939)
d <- c(150,615,2923,939, 1245, 622, 540, 238)


draw.quad.venn(area1 = sum(a), area2 = sum(b), area3 = sum(c), area4 = sum(d), 
               n12 = sum(a[5:8]), n13 = sum(a[c(2,3,6,7)]), n14 = sum(a[c(3,4,7,8)]), 
               n23 = sum(b[c(2,3,6,7)]), n24 = sum(b[c(3,4,7,8)]), 
               n34 = sum(c[5:8]),
               n123 = sum(a[6:7]),
               n134 = sum(a[c(3,7)]),
               n124 = sum(a[7:8]),
               n234 = sum(b[c(3,7)]),
               n1234 = 2923, category = c("A","B","C","D"), 
               fill = colorspace::rainbow_hcl(4),
               col = colorspace::rainbow_hcl(4)[c(1,3,4,2)], lwd = rep(1, 4))

enter image description here