[BioC] Venn Diagram for 2, 3 and 4 sets (can be extended for more)

Liqun He liqun.he at ki.se
Sat Oct 6 12:43:47 CEST 2007


Dear Gordon and those who are interested in Venn diagrams,

I once wrote a code to plot Venn diagrams for 5 groups in R with ellipses,
in order to compare 5 gene lists in my project. The code to plot 5 Venn
diagrams is listed below (code wrote under R version 2.4.1). 
I have a complete long function from input data to output plot. But the
function needs to be generalized and code notes need to be added so that
others can easily understand and use it. Unfortunately, I will be fully
involved with other things in the coming few weeks. 
If you think the shape of this Venn diagrams for 5 groups are acceptable. I
can paste back a complete function in several weeks. 
I guess I can also make a function of Venn diagrams for 4 groups as well, I
will paste the function.
Any comments are welcome!

Regards,
Liqun He
Karolinska Institute, Stockholm

#######################################

elps=cbind(150*cos(seq(0,2*pi,len=1000)), 60*sin(seq(0,2*pi,len=1000)))

relocate_elp=function(e, alpha, x, y){
phi=(alpha/180)*pi;
xr=e[,1]*cos(phi)+e[,2]*sin(phi)
yr=-e[,1]*sin(phi)+e[,2]*cos(phi)
xr=x+xr;
yr=y+yr;
return(cbind(xr, yr))
}

plot(c(0, 400), c(0, 400), type="n", axes=F, ylab="", xlab="")

polygon(relocate_elp(elps, 90,200, 250))
polygon(relocate_elp(elps, 162,250, 220))
polygon(relocate_elp(elps, 234,250, 150))
polygon(relocate_elp(elps, 306,180, 125))
polygon(relocate_elp(elps, 378,145, 200))

text(50, 280, "Data set A")
text(150,400, "Data set B")
text(350,300, "Data set C")
text(350,20, "Data set D")
text(50,10, "Data set E")

text(61, 228, "A");
text(194, 329, "B");
text(321, 245, "C");
text(290, 81, "D");
text(132, 69, "E");

text(146, 250, "AB", cex=0.45) 
text(123, 188, "AC", cex=0.45) 
text(275, 152, "AD", cex=0.45) 
text(137, 146, "AE", cex=0.45) 
text(243, 268, "BC", cex=0.45) 
text(175, 267, "BD", cex=0.45) 
text(187, 117, "BE", cex=0.45) 
text(286, 188, "CD", cex=0.45) 
text(267, 235, "CE", cex=0.45) 
text(228, 105, "DE", cex=0.45) 

text(148, 210, "ABC",cex=0.45)
text(159, 253, "ABD",cex=0.45) 
text(171, 141, "ABE",cex=0.45) 
text(281, 175, "ACD",cex=0.45) 
text(143, 163, "ACE",cex=0.45) 
text(252, 145, "ADE",cex=0.45) 
text(205, 255, "BCD",cex=0.45) 
text(254, 243, "BCE",cex=0.45) 
text(211, 118, "BDE",cex=0.45) 
text(267, 211, "CDE",cex=0.45) 

text(170, 231,"ABCD",cex=0.45) 
text(158, 169,"ABCE",cex=0.45) 
text(212, 139,"ABDE",cex=0.45)
text(263, 180,"ACDE",cex=0.45) 
text(239, 232,"BCDE",cex=0.45)
 
text(204,190,"ABCDE")

#######################################

-----Original Message-----
From: bioconductor-bounces at stat.math.ethz.ch
[mailto:bioconductor-bounces at stat.math.ethz.ch] On Behalf Of Gordon Smyth
Sent: Saturday, October 06, 2007 8:16 AM
To: Steffen Moeller
Cc: bioconductor at stat.math.ethz.ch
Subject: [BioC] Venn Diagram for 2, 3 and 4 sets (can be extended for more)

Dear Steffen,

In principle I'd be very happy to extend the vennDiagram() function 
in limma to more than 3 groups. So please send me your code. Your 
email seems too good to be true though, because it's geometrically 
impossible to draw Venn diagrams for 4 groups with circles. Venn 
diagrams can be done with 4 groups by going to elllipses. With more 
than 5 groups, Venn diagrams seem to me to be so complicated as to be 
perhaps no longer useful. The geometric theory of Venn diagrams has 
been worked out by the statistician AWF Edwards, see eg his book 
"Cogwheels of the Mind".

Best wishes
Gordon

>Date: Fri, 5 Oct 2007 10:50:23 +0200
>From: Steffen Moeller <steffen_moeller at gmx.de>
>Subject: [BioC] Venn Diagram for 2, 3 and 4 sets (can be extended for
>         more)
>To: bioconductor at stat.math.ethz.ch
>
>Dear all,
>
>I needed Venn Diagrams to accomodate 4 sets rather than the 3 that I got
via
>the limma package and I could not find it elsewhere.
>
># Some test data
>A<- 1:20
>B<- 1:20
>C<- 2:20
>D<- 3:21
>
># input gathered into a list, the names
># appear in the diagram
>input<-list(a=A,b=B,c=C,d=D)
>
># calculation of values that should
># go into all the fields
>vc <- getVennCounts(input)
>
># drawing of diagram
>drawVennDiagram(vc)
>
>The diagrams look like the ones from limma, i.e., no variation of 
>circle shape
>and to reflect the size of the sets. The only novelty is that is also works
>on 4 sets and it is avoiding the use of classes.
>
>What should I do with these 295 lines of code now? It does not seem 
>enough for
>a package on its own. Is anybody interested? Gordon?
>
>Cheers,
>
>Steffen

_______________________________________________
Bioconductor mailing list
Bioconductor at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/bioconductor
Search the archives:
http://news.gmane.org/gmane.science.biology.informatics.conductor



More information about the Bioconductor mailing list