Search code examples
rvenn-diagram

Missing sets in Venn Diagram using `ggvenn` in `R`


I have a list with 7 sets of data. The following code

genes <- paste("gene",1:1000,sep="")
x <- list(
   A = sample(genes,300), 
   B = sample(genes,525), 
   C = sample(genes,440),
   D = sample(genes,350),
   E = sample(genes,100),
   EE = sample(genes,120),
   G = sample(genes,102))

library(ggvenn)
ggvenn(x,  stroke_size = 0.5, set_name_size = 4)

produces the Venn Diagram of them, but I obtained only 4 sets in the resulting plot:

enter image description here

How do I get the Venn Diagram of all the sets? Moreover, I would like the elements that are inside each set to be listed (for example the first ten elements of each set, since there are many).


Solution

  • To draw your diagram use venn::venn(x) from the venn package. However, to obtain the elements inside use attributes(gplots::venn(x, show.plot = FALSE))$intersections from the gplots package.

    venn

    If you are only interested in the first 10 elements, this would work: sapply(attributes(gplots::venn(x, show.plot = FALSE))$intersections, function(x) x[1:10])