30

Are there any other packages for doing Venn diagrams in R besides the limma package?

Anyone got tips?

Here's some notes on doing Venn diagrams with the limma packages.

Axeman
  • 32,068
  • 8
  • 81
  • 94
JD Long
  • 59,675
  • 58
  • 202
  • 294
  • 3
    Hi, I'm still looking for a package that will draw proportional Venn diagrams. Here's the closest thing that I found from 8 years ago, https://stat.ethz.ch/pipermail/r-help/2003-February/029393.html. I was hoping that there would be a more recent development with this. – andrewj Mar 03 '11 at 21:58
  • 1
    http://www.caleydo.org/tools/upset/ – wikiselev Dec 05 '16 at 14:33

8 Answers8

18

List of Venn Diagram packages:

zx8754
  • 52,746
  • 12
  • 114
  • 209
bala
  • 553
  • 4
  • 7
10

There is Vennerable package on R-forge.

source("http://bioconductor.org/biocLite.R")
biocLite(c("graph", "RBGL", "gtools", "xtable"))
install.packages("Vennerable", repos="http://R-Forge.R-project.org")

Venn diagram

Marek
  • 49,472
  • 15
  • 99
  • 121
7

This comes very late but it might useful for others searching for an answer: VennDiagram, on CRAN here.

It allows multiple sets (four sets for venn, 3 sets for Euler diagrams), customizable colours and fonts, simple syntax and and best of all the size of the circles is proportional to the size of the data sets (at least when comparing 2 data sets). To install:

install.packages("VennDiagram")
library(VennDiagram)

For those using bioconductor packages and working with genomic coordinates, recently vennDiagram was implemented in the package ChIPpeakAnno (version 2.5.12) and allows pretty intersections of Genomic coordinates of, for instance, Chip-seq peaks. For early adopters you might need to install the development package.

peaks1 = RangedData(IRanges(start = c(967654, 2010897, 2496704),
    end = c(967754, 2010997, 2496804), names = c("Site1", "Site2", "Site3")),
    space = c("1", "2", "3"), strand=as.integer(1),feature=c("a","b","f"))

peaks2 = RangedData(IRanges(start = c(967659, 2010898,2496700,3075866,3123260),
    end = c(967869, 2011108, 2496920, 3076166, 3123470),
    names = c("t1", "t2", "t3", "t4", "t5")),
    space = c("1", "2", "3", "1", "2"), strand = c(1, 1, -1,-1,1), feature=c("a","b","c","d","a"))

makeVennDiagram(RangedDataList(peaks1,peaks2, peaks1, peaks2), NameOfPeaks=c("TF1", "TF2","TF3", "TF4"),
     totalTest=100,useFeature=TRUE, main="Venn Diagram",
    col = "transparent",fill = c("cornflowerblue", "green", "yellow", "darkorchid1"),
    alpha = 0.50,label.col = c("orange", "white", "darkorchid4", "white", "white", "white", "white", "white", "darkblue", "white", "white", "white", "white", "darkgreen", "white"), cat.col = c("darkblue", "darkgreen", "orange", "darkorchid4"))
Stephan Kolassa
  • 7,953
  • 2
  • 28
  • 48
fridaymeetssunday
  • 1,118
  • 1
  • 21
  • 31
7

The venn function in the gplots package is also useful if you need to create Venn Diagram of 4/5 sets.

Paolo
  • 2,795
  • 1
  • 20
  • 23
7

I use two custom functions that to the trick. My implementation of venndia plots the venn diagram and returns lists of overlaps between A and B (and C). See the code below.

With these, you can

vd <- venndia(A=LETTERS[1:15], B=LETTERS[5:20], getdata=TRUE)

which will both plot and return the data. you can switch off returning the data by doing

venndia(A=LETTERS[1:15], B=LETTERS[5:20])

since getdata is FALSE by default. /Daniel

circle <- function(x, y, r, ...) {
    ang <- seq(0, 2*pi, length = 100)
    xx <- x + r * cos(ang)
    yy <- y + r * sin(ang)
    polygon(xx, yy, ...)
}

venndia <- function(A, B, C, getdata=FALSE, ...){
    cMissing <- missing(C)
    if(cMissing){ C <- c() }

    unionAB <- union(A, B)
    unionAC <- union(A, C)
    unionBC <- union(B, C)
    uniqueA <- setdiff(A, unionBC)
    uniqueB <- setdiff(B, unionAC)
    uniqueC <- setdiff(C, unionAB)
    intersAB <- setdiff(intersect(A, B), C)
    intersAC <- setdiff(intersect(A, C), B)
    intersBC <- setdiff(intersect(B, C), A)
    intersABC <- intersect(intersect(A, B), intersect(B, C))

    nA <- length(uniqueA)   
    nB <- length(uniqueB)
    nC <- length(uniqueC)

    nAB <- length(intersAB)
    nAC <- length(intersAC)
    nBC <- length(intersBC)

    nABC <- length(intersABC)   

    par(mar=c(2, 2, 0, 0))
    plot(-10, -10, ylim=c(0, 9), xlim=c(0, 9), axes=FALSE, ...)
    circle(x=3, y=6, r=3, col=rgb(1,0,0,.5), border=NA)
    circle(x=6, y=6, r=3, col=rgb(0,.5,.1,.5), border=NA)
    circle(x=4.5, y=3, r=3, col=rgb(0,0,1,.5), border=NA)

    text( x=c(1.2, 7.7, 4.5), y=c(7.8, 7.8, 0.8), c("A", "B", "C"), cex=3, col="gray90" )

    text(
        x=c(2, 7, 4.5, 4.5, 3, 6, 4.5), 
        y=c(7, 7, 2  , 7  , 4, 4, 5), 
        c(nA, nB, nC, nAB, nAC, nBC, nABC), 
        cex=2
    )

    if(getdata){
        list(A=uniqueA, B=uniqueB, C=uniqueC, 
            AB=intersAB , AC=intersAC , BC=intersBC , 
            ABC=intersABC
        )
    }
}
Daniel
  • 12,445
  • 4
  • 21
  • 18
6

Duncan Murdoch has a venn package, which is not on CRAN. (hat tip to Gabor Grothendieck)

You can also read about it in the "Journal of Statistical Software".

ThatGuy
  • 409
  • 2
  • 6
  • 9
Shane
  • 98,550
  • 35
  • 224
  • 217
0

Here is reference to another version for 3-variable data: http://elliotnoma.wordpress.com/2011/02/09/venn-diagram/

The code is also available in the package colorfulVennPlot: http://cran.r-project.org/web/packages/colorfulVennPlot/index.html

Community
  • 1
  • 1
pitabread
  • 71
  • 1
  • 4
  • 2
    Please note that you should post the useful points of an answer here, on this site, or your post risks being deleted as ["Not an Answer"](http://meta.stackexchange.com/q/8259). You may still include the link if you wish, but only as a 'reference'. The answer should stand on its own without needing the link. – Andrew Barber Jan 31 '13 at 19:32
0

I would recommend the package VennDiagram: http://cran.r-project.org/web/packages/VennDiagram/VennDiagram.pdf

On pake 19 you will find 10 pakes of very good examples (both advanced and simplified ones). As of yet I have not found anything that it can't do that I need it to do.

Stenemo
  • 611
  • 7
  • 13