Miguel
Miguel

Reputation: 356

Venn diagram from count table using R

Is there a way to create a venn diagram in R from a count table like this one? A has in total 8 elements, of which 5 are shared with B; 5 are shared with C; and 3 are shared with D. Among these, 4 are shared between A, B and C; 2 between A, B and D; and so on. Looking at the existing packages (limma, VennDiagram), it looks like they are not designed to deal with this sort of table.

group   n_elements
A       8
B       8
C       9
D       7
A+B     5
A+C     5
A+D     3
B+C     6
B+D     4
C+D     4
A+B+C   4
A+B+D   2
A+C+D   2
B+C+D   3
A+B+C+D 2

Upvotes: 1

Views: 1095

Answers (1)

Johan Larsson
Johan Larsson

Reputation: 3694

You can do this with my package eulerr. You just have to put your results in a named numeric vector. Consider the following example. (Below I have constructed an area-proportional euler diagram, but if you want a venn diagram just call venn() instead.)

group <- c("A", "B", "A&B")
n_elements <- c(8, 8, 9)
names(n_elements) <- group

library(eulerr)

set.seed(1)
res <- euler(n_elements)

plot(res)

Created on 2020-01-09 by the reprex package (v0.3.0)

Upvotes: 1

Related Questions