Home > Software design >  Creating a Venn diagram with elements outside of circles in R
Creating a Venn diagram with elements outside of circles in R

Time:10-03

I'd like to create a Venn diagram with elements that are not contained in either circle. That is, some elements are part of set A, some elements are part of set B, some elements are in the intersection of the two sets, and other elements are not members of either set.

I can create the two circles that symbolized sets A and B using this code:

library(ggplot2)
library(ggvenn)
list_venn <- list(
  A = 1:6,
  B = 5:11,
  C = 12:14
)
ggvenn(list_venn, c("A", "B"))

But I would like that elements 12:14 (object C) would be represented outside the two circles since they are members of neither. How can I achieve that?

CodePudding user response:

You could try this with ggplot2::annotate(). Not sure how you want the information for set C to appear but you could use the various formatting arguments for text.

library(ggplot2)
library(ggvenn)

list_venn <- list(
  A = 1:6,
  B = 5:11,
  C = 12:14
)
ggvenn(list_venn, c("A", "B")) 
  annotate("text", x = 0, y = -1.5, label = "C\n0\n0%", size = 6)

Created on 2022-10-02 with reprex v2.0.2

  • Related