# What type of graphs can be used to show overlap between many sets?

I have a dataset with 90 different sets of GO terms (e.g. one set would be ("GO:0014075", "GO:0060742", "GO:2001238", "GO:0071478"). I want to plot the overlap between all of these groups. I don't know what, if any, type of plots are used for showing overlap between many groups. For a smaller set of groups I could use a venn diagram, but this does not work with a large group of comparisons.

What type of plot can be used for plotting the overlap between many groups?

• How many different terms does the union of your sets contain? Apr 7 '14 at 9:57
• @StephanKolassa 267
– Niek
Apr 7 '14 at 10:55

Would something like this be a start? This shows which terms show up in which sets. Intersections on specific terms are given by dots at the same $x$ position.

The ordering may be helpful... or it may be misleading. You will have to consider your specific application.

Of course, the problem is that we can't distinguish the sets (the $y$ axis labels) any more. I suspect that this will always be hard with 90 groups. Possibilities may be:

• Limiting the plot to "important" groups (defined according to your specific application)
• Grouping sets into groups of horizontal dots
• Working with colors if sets can be grouped meaningfully
• Only putting every second set name on the left side, and the others on the right

The same problem will occur if you have more than 20 terms overall. Similar remedies may be possible.

R code:

set.seed(1)
terms <- sprintf("%07i",round(100000*runif(20),0))

sets <- sapply(1:90,FUN=function(y)sample(x=terms,size=rpois(1,2)+1))
names(sets) <- paste("A",1:length(sets),sep="")

tab <- t(sapply(sets,function(xx)table(factor(xx,levels=terms))))
tab <- tab[,order(colSums(tab),decreasing=TRUE)]
tab <- tab[rev(do.call(order,as.data.frame(tab))),]

plot(c(1,length(terms)),c(1,length(sets)),type="n",xlab="",ylab="",xaxt="n",yaxt="n")
abline(h=seq_along(sets),col="grey",lty=3)
for ( ii in 1:nrow(tab) ) points(which(tab[ii,]==1),rep(nrow(tab)-ii+1,sum(tab[ii,])),pch=19)
axis(side=1,at=seq_along(terms),labels=colnames(tab),las=3)
axis(side=2,at=seq_along(sets),labels=rownames(tab),las=2)

• I can break it up in three groups of 30, and when I remove the x-axis labels it looks quite good. Thanks!
– Niek
Apr 7 '14 at 11:05