Search code examples
rvenn-diagram

3 set venn diagram with venneuler


This is my code to create a 3-set venn diagram with the R package venneuler, inserting two rows of data in each circle and intersection (representing up and down regulated genes). I share it with you because it took me a while to find this solution.

library(venneuler)
MyVenn <- venneuler(c(A=2,B=2,C=2,"A&B"=0.8,"A&C"=0.7,"B&C"=0.8,"A&B&C"=0))
MyVenn$labels <- c("","","")
MyVenn$diameters<-c(0.4,0.4,0.4)
plot(MyVenn, col="grey80", border = "black")
          text(0.35,0.6,"181\n161", cex = 1.5) #A
          text(0.65,0.6,"27\n14", cex = 1.5) #B
          text(0.4997455,0.325,"0\n0", cex = 1.5) #C
          text(0.5,0.6,"0\n0", cex = 1.5) #AB,
          text(0.59,0.45,"0\n0", cex = 1.5)  #BC
          text(0.4,0.45,"0\n0", cex = 1.5)  #AC
          text(0.5,0.5,"0\n0", cex = 1.5) #ABC

And this is how it looks like (it is saved as 500x500): enter image description here

I don't know though how to add labels outside the circles, suggestions, corrections, improvements are welcome


Solution

  • Just add them manually as you did before, with text():

    text(MyVenn$centers[1, 1] + 0.2, MyVenn$centers[1, 2] + 0.2, "B", cex = 2)
    text(MyVenn$centers[2, 1] + 0.2, MyVenn$centers[2, 2] - 0.2, "C", cex = 2)
    text(MyVenn$centers[3, 1] - 0.2, MyVenn$centers[3, 2] + 0.2, "A", cex = 2)
    

    Imgur