2

I have the folowing dataframe:

SET1 SET2 SET3
par1 par2 par1
par2 par3 par2
par3 par4 par5
...  ...  ...

I would like to make a Venn diagram in that all those 'parX' elements are shown in respective subets i.e. as labels, not just the number of overlapping elements. Which R package supports that?

mjs
  • 150
  • 1
  • 20

1 Answers1

4

Regarding the best answer from here you have to add labels manually (using VennDiagram), when you have two circles it's pretty easy, however if you have three or more, whole stuff becames more complex

library(VennDiagram)



SET1 <- c('a','b','c','d')
SET2 <- c('a','e','f','g')
SET3 <- c('a','w','x','f')



v <- venn.diagram(list(SET1 = SET1, SET2 = SET2, SET3 = SET3),
                  fill = c("red", "green","blue"),
                  alpha = c(0.5, 0.5, 0.5), cat.cex = 1.5, cex=1.5,
                  filename=NULL)
grid.newpage()
grid.draw(v)


v[[7]]$label  <- paste(setdiff(SET1, intersect(SET2,SET3)), collapse="\n") 
v[[8]]$label <- paste(setdiff(intersect(SET1,SET2),intersect(SET1, intersect(SET2,SET3))), collapse="\n")
v[[9]]$label <- paste(setdiff(SET2, intersect(SET1,SET3)), collapse="\n")
v[[10]]$label <- paste(setdiff(intersect(SET3,SET1),intersect(SET3, intersect(SET1,SET2))), collapse="\n")
v[[11]]$label <- paste(intersect(SET1, intersect(SET2,SET3)), collapse="\n")
v[[12]]$label <- paste(setdiff(intersect(SET2,SET3),intersect(SET2, intersect(SET1,SET3))), collapse="\n")
v[[13]]$label <- paste(setdiff(SET3, intersect(SET1,SET2)), collapse="\n")


grid.newpage()
grid.draw(v)

enter image description here

Adamm
  • 2,150
  • 22
  • 30
  • 1
    Thank you, that's what I was looking for! – mjs Jan 25 '19 at 15:17
  • Btw, if I have many elements, as in most real-life applications, the representation is less then ideal - are there any ways to fit all elements into the subsets where they belong? – mjs Jan 25 '19 at 15:42
  • 1
    Actually the separator used in the example above is new line, so we have columns in circles. I think the better way to do such visualisation is `ggplot`. Nice described [here](https://scriptsandstatistics.wordpress.com/2018/04/26/how-to-plot-venn-diagrams-using-r-ggplot2-and-ggforce/) – Adamm Jan 28 '19 at 06:44