title: Get the list of items in Venn diagram
body: <p>It is easy to the draw a Venn diagram with the following code:</p>
  
  <pre><code>library(VennDiagram)
  
  set.seed(1) # For reproducibility of results
  xx.1 &lt;- list(A = sample(LETTERS, 15), B = sample(LETTERS, 15), 
               C = sample(LETTERS, 15), D = sample(LETTERS, 15))
  
  venn.diagram(xx.1, filename ="1.tiff", height = 1000, width = 1000)
  </code></pre>
  
  <p><img src="https://i.imgur.com/IalHBjs.png" alt="A venn diagram with four sets"></p>
  
  <p>But how do I figure out the items in each field? For example, I would like to know what are the two letters only found in A? </p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>Here is my solution, it is not perfect but could give all the intersections.</p>
  
  <pre><code>library(reshape)
  library(R.utils)
  
  ## data
  A &lt;- data.frame(names = sample(LETTERS, 15), A = 1)
  B &lt;- data.frame(names = sample(LETTERS, 15), B = 1)
  C &lt;- data.frame(names = sample(LETTERS, 15), C = 1)
  D &lt;- data.frame(names = sample(LETTERS, 15), D = 1)
  
  ## a merged data frame.
  xx.1 &lt;- list(A = A, B= B, C= C, D = D)
  xx.2 &lt;- merge_recurse(xx.1)
  
  ## function
  ff.vennFourItems &lt;- function(X)
  {
      ## get the items from venn diagram; for four sets, there are 15 fields;
  
      vennItems &lt;- list()
      cate.n &lt;- names(X)[2:5]
  
      for (i in 1:15)
      {
          xx.b &lt;- intToBin(i)
          ## make it four bits;
          if (nchar(xx.b) != 4)
          {
              xx.b &lt;- paste(paste(rep("0", 4 - nchar(xx.b)), collapse = ""), xx.b, sep ="") 
          }
  
          xx.b.1 &lt;- unlist(strsplit(xx.b, ""))
  
          xx.1 &lt;- X
  
          if(xx.b.1[1] == "0") { xx.1 &lt;- xx.1[is.na(xx.1[, 2]), ] }
          else { xx.1 &lt;-  xx.1[!is.na(xx.1[, 2]), ] }
  
          if(xx.b.1[2] == "0") { xx.1 &lt;- xx.1[is.na(xx.1[, 3]), ] }
          else { xx.1 &lt;-  xx.1[!is.na(xx.1[, 3]), ] }
  
          if(xx.b.1[3] == "0") { xx.1 &lt;- xx.1[is.na(xx.1[, 4]), ] }
          else { xx.1 &lt;-  xx.1[!is.na(xx.1[, 4]), ] }
  
          if(xx.b.1[4] == "0") { xx.1 &lt;- xx.1[is.na(xx.1[, 5]), ] }
          else { xx.1 &lt;-  xx.1[!is.na(xx.1[, 5]), ] }
  
          chipC &lt;-  paste(paste(cate.n, collapse = "#"), xx.b, sep = "***")
  
          if (dim(xx.1)[1] == 0) 
          {
              xx.2 &lt;- list(genes = dim(xx.1)[1], chipC = chipC, chipCN = i, detailChipS = xx.1, shortL = data.frame(genes = "noInteraction", cl = i, fullCl = chipC))
          }
          else
          {
              xx.2 &lt;- list(genes = dim(xx.1)[1], chipC = chipC, chipCN = i, detailChipS = xx.1, shortL = data.frame(genes = as.character(xx.1[, 1]), cl = i, fullCl = chipC))
          }
          vennItems &lt;- c(vennItems, list(xx.2))
      }
  
      vennItems
  }
  
  xx.3 &lt;- ff.vennFourItems(xx.2)
  str(xx.3)
  List of 15
   $ :List of 5
    ..$ genes      : int 1
    ..$ chipC      : chr "A#B#C#D***0001"
    ..$ chipCN     : int 1
    ..$ detailChipS:'data.frame': 1 obs. of  5 variables:
    .. ..$ names: Factor w/ 25 levels "A","B","E","F",..: 25
    .. ..$ A    : num NA
    .. ..$ B    : num NA
    .. ..$ C    : num NA
    .. ..$ D    : num 1
    ..$ shortL     :'data.frame': 1 obs. of  3 variables:
    .. ..$ genes : Factor w/ 1 level "Z": 1
    .. ..$ cl    : int 1
    .. ..$ fullCl: Factor w/ 1 level "A#B#C#D***0001": 1
   $ :List of 5
    ..$ genes      : int 0
    ..$ chipC      : chr "A#B#C#D***0010"
    ..$ chipCN     : int 2
  </code></pre>