11

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()
Sathish
  • 12,453
  • 3
  • 41
  • 59
Rechlay
  • 1,457
  • 2
  • 12
  • 19

2 Answers2

10

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

emilliman5
  • 5,816
  • 3
  • 27
  • 37
  • 1
    Can you tell me how can I find which of the vectors is not correct based on such error: `Error in draw.quad.venn(area1 = sum(a), area2 = sum(b), area3 = sum(c), : Impossible: a15 <- n12 - a6 - a11 - a12 produces negative area` – Rechlay May 15 '17 at 12:58
  • Sorry for comment after the first one. I would like to just know what kind of order should I used when I create a vector of numbers. – Rechlay May 15 '17 at 13:22
  • For the left to sets I made the vector starting at the upper left, and went down. For the right groups I started in the upper right and went down. It should be apparent if you look at my vectors and your original venn. – emilliman5 May 15 '17 at 13:59
  • 1
    Why don't you just plot numbers on top of an empty png of the diagram you show in the example ? It seems simple and then you keep your original design. And you choose whatever order you like :). – moodymudskipper May 19 '17 at 08:57
0

have you tried the Venn Diagram package

https://cran.r-project.org/web/packages/VennDiagram/VennDiagram.pdf

and see this too

Venn Diagrams with R?

Community
  • 1
  • 1
Ajay Ohri
  • 3,382
  • 3
  • 30
  • 60