Friday, February 29, 2008

R Create Venn diagram

Using the package limma to draw the venn diagram.

Code:
-----------------------------------------------
A1 <- c("A", "B");
A2 <- c("A", "B", "C");
A3 <- c("D", "B");

library(limma);
SET.list <- list(A1=A1, A2=A2, A3=A3);
len <- length(SET.list);
all.unique <- unique(unlist(SET.list));
tmp <- matrix(0, ncol=len, nrow=length(all.unique));
colnames(tmp) <- names(SET.list);
rownames(tmp) <- all.unique;
for(ith in 1:len){
tmp[SET.list[[ith]], ith] <- 1;
}
count.sum <- apply(tmp, 1, sum);
count.sum
if(len < 4){
windows();
vennDiagram(vennCounts(tmp), main = "gene.intersection", cex = 1)
}
-----------------------------------------------

No comments: