Tan Hui Hui Jenny wrote:
I'm trying to plot Venn diagrams with more than 3 sets (5 actually) in order to 
describe graphically the genetic variation between populations.
I tried the limma library but realised it can only plot 3 sets. Is there any solution? Of course I could plot the chart manually but it'll take too long (have other datasets)..... One of my dataset is given below.
Hi Jenny,

Best I could do is four sets. The code is a bit rough but consistent with the vennDiagram function in the limma package.

Jim
show.circle<-function(x,y,radius,border=NULL,col=NA) {
 angles<-seq(0,2*pi,by=0.04*pi)
 xpos<-cos(angles)*radius+x
 ypos<-sin(angles)*radius+y
 polygon(xpos,ypos)
}
 
venn4<-function(vo,mar=rep(1,4)) {
 dimvo<-dim(vo)
 if(dimvo[2] != 4)
  stop("Usage: venn4(vo,mar=rep(1,4))/n/twhere vo has 4 columns")
 plot(0,0,type="n",xlim=c(-2,2),ylim=c(-2,2),xlab="",ylab="",axes=FALSE)
 par(mar=mar)
 show.circle(-0.5,0.5,1.5)
 show.circle(0.5,0.5,1.5)
 show.circle(-0.5,-0.5,1.5)
 show.circle(0.5,-0.5,1.5)
 outside<-sum(apply(vo,1,sum) == 0)
 text(-1.2,1.4,"A")
 text(1.2,1.4,"B")
 text(-1.2,-1.1,"C")
 text(1.2,-1.1,"D")
 text(0,1.4,"AB")
 text(-1.3,0.15,"AC")
 text(1.2,0.15,"BD")
 text(0,-1.1,"CD")
 text(-0.6,0.9,"ABC")
 text(0.6,0.9,"ABD")
 text(-0.83,-0.5,"ACD")
 text(0.83,-0.5,"BCD")
 text(0,0.1,"ABCD")
 par(xpd=TRUE,cex=1.5)
 text(0,-2.4,outside)
 onlyone<-apply(vo,1,sum) == 1
 A<-sum(onlyone & vo[,1])
 text(-1.2,1.1,A)
 B<-sum(onlyone & vo[,2])
 text(1.2,1.1,B)
 C<-sum(onlyone & vo[,3])
 text(-1.2,-1.4,C)
 D<-sum(onlyone & vo[,4])
 text(1.2,-1.4,D)
 onlytwo<-apply(vo,1,sum) == 2
 AB<-sum(onlytwo & vo[,1] & vo[,2])
 text(0,1.1,AB)
 AC<-sum(onlytwo & vo[,1] & vo[,3])
 text(-1.3,-0.15,AC)
 BD<-sum(onlytwo & vo[,2] & vo[,4])
 text(1.2,-0.15,BD)
 CD<-sum(onlytwo & vo[,3] & vo[,4])
 text(0,-1.4,CD)
 onlythree<-apply(vo,1,sum) == 3
 ABC<-sum(onlythree & vo[,1] & vo[,2] & vo[,3])
 text(-0.74,0.65,ABC)
 ABD<-sum(onlythree & vo[,1] & vo[,2] & vo[,4])
 text(0.74,0.65,ABD)
 ACD<-sum(onlythree & vo[,1] & vo[,3] & vo[,4])
 text(-0.7,-0.75,ACD)
 BCD<-sum(onlythree & vo[,2] & vo[,3] & vo[,4])
 text(0.7,-0.75,BCD)
 ABCD<-sum(apply(vo,1,sum) == 4)
 text(0,-0.2,ABCD)
 par(mar=c(5,4,4,2)+0.1,xpd=FALSE,cex=1)
}
______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to