Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

4-way Venn Diagram in R?

Tags:

r

venn-diagram

I am trying to make an 4-Way Venn Diagram in R. I have this data which I want to put in the diagram:

enter image description here

Can anyone give me a suggestion how to do it? I try to use the function vennDiagram() but that does not work, because it is a 4way diagram.

I am also trying to use the package VennDiagram, but is really confusing the way the data is "allocated" to the right place in the diagram. I am using this code:

library (VennDiagram)
venn.diagram(
    x=list(
    I=c(1:18,19:31,32:119,125:129,130:192,193:144,145:326,327:373),
    VI=c(516:542,510:515,420:497,498:509,145:326,327:373,130:192,193:144),
    II=c(19:31,32:119,145:326,327:373,374:378,378:419,420:497,498:509),
    III=c(506:509,378:419,32:119,125:129,130:192,145:326,420:497,510:515)
    ),
    filename = "4Way_Venn.tiff",
    col = "black",
    lty = "dotted",
    lwd = 4,
    fill = c("cornflowerblue", "green", "yellow", "darkorchid1"),
    alpha = 0.50,
    label.col = c("orange", "white", "darkorchid4", "white", "white", "white", 
                  "white", "white", "darkblue", "white", "white", "white", 
                  "white", "darkgreen", "white"),
    cex = 2.5,
    fontfamily = "serif",
    fontface = "bold",
    cat.col = c("darkblue", "darkgreen", "orange", "darkorchid4"),
    cat.cex = 2.5,
    cat.fontfamily = "serif"
    );

Can anyone help me? maybe with an easier solution then the one using the VennDiagram package.

like image 342
Peiska Avatar asked Nov 20 '25 03:11

Peiska


1 Answers

I might be missing the point here but I am not sure how do you want to use those 'counts' in making your venn diagram? From the columns 'c1' to 'c4' you can very easily make venn diagram using venneuler package:

require(venneuler)
#here I replicate your data
#because it's repeatable, you can use `rep` function to generate it
c1 <- rep(c(0,1),each=8)
c2 <- rep(c(0,1),each=4,times=2)
c3 <- rep(c(0,1),each=2,times=4)
c4 <- rep(c(0,1),times=8)
#put your data into matrix
m <- as.matrix(data.frame(C1=c1,C2=c2,C3=c3,C4=c4))
#plot it
v = venneuler(m)
plot(v)

enter image description here

like image 124
Geek On Acid Avatar answered Nov 21 '25 18:11

Geek On Acid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!