3

In R, I have a Venn diagram encoded as follows:

[[1]]
[[1]][[1]]
[1] FALSE  TRUE # B

[[1]][[2]]
[1] 1


[[2]]
[[2]][[1]]
[1] TRUE TRUE # A and B

[[2]][[2]]
[1] 1


[[3]]
[[3]][[1]]
[1]  TRUE FALSE # A

[[3]][[2]]
[1] 2

That means there are two sets, say A and B, because the first element of each list is a vector of two Boolean values. The Venn diagram has three zones, because there are three lists. The second element of each list gives then number of elements included in the corresponding zone.

How can I plot this Venn diagram?

3
  • Do you need a general solution for any combination of letters or just two letters? Commented Mar 4 at 10:48
  • 1
    @user2974951 A general solution. Commented Mar 4 at 10:54
  • Is it absolutely necessary to deal with this multi-depth list format, or could you rewrite your "partition generator" to produce a list or array more in line with the various Venn packages? Commented Mar 4 at 17:03

1 Answer 1

1

I think I've found, using ggVennDiagram::plot_venn:

library(ggVennDiagram)
nsets <- 2
shd <- get_shape_data(nsets)
id <- shd$regionLabel$id

newDiagram <- integer(length(diagram))
ids <- nms <- character(length(diagram))
for(i in seq_along(diagram)) {
  ids[i] <- paste0((1:nsets)[diagram[[i]][[1]]], collapse = "/")
  nms[i] <- paste0(LETTERS[1:nsets][diagram[[i]][[1]]], collapse = "/")
  newDiagram[i] <- diagram[[i]][[2]]
}
names(newDiagram) <- ids

library(tibble)
shd$regionData <- tibble(id = ids, count = newDiagram[ids], name = nms)
shd$regionLabel$count <- newDiagram[id]
shd$regionLabel$name <- nms
shd$setData <- tibble(name = LETTERS[1:nsets])
shd$setLabel$name <- LETTERS[1:nsets]

plot_venn(shd)

Not the answer you're looking for? Browse other questions tagged or ask your own question.