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

Gordon Smyth smyth at wehi.EDU.AU
Sun Oct 7 09:35:17 CEST 2007


Dear Liqun,

This looks quite an elegant solution. I'm sure that many users would 
find it valuable if you can wrap it up into a user funtion for 4 or 5 sets.

Best wishes
Gordon

>From: Liqun He [mailto:liqun.he at ki.se]
>Sent: Saturday, October 06, 2007 12:44 PM
>To: 'bioconductor at stat.math.ethz.ch'
>Subject: RE: [BioC] Venn Diagram for 2, 3 and 4 sets (can be extended for
>more)
>
>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")
>
>#######################################



More information about the Bioconductor mailing list