knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

How to use Venn Calculator?

ggVennDiagram has a series of set operation functions, and this can be used as the Venn calculator.

library(ggVennDiagram)
set.seed(20231225)
y = list(
  A = sample(letters, 8) |> sort(),
  B = sample(letters, 8) |> sort(),
  C = sample(letters, 8) |> sort(),
  D = sample(letters, 8) |> sort())

y

First of all, we need to construct a Venn class object with this list. If you print this object, it will give meta information of the object.

venn_y = Venn(y)

venn_y

r overlap(venn_y, 1:2) # members in both the first two sets overlap(venn_y) # members in all the sets

r discern(venn_y, 1) # members in set 1, but not in the resting sets discern(venn_y, c("A","B"), 3) # members in set A & B, but not in the 3rd set

r discern_overlap(venn_y, 1) # specific items in set 1 discern_overlap(venn_y, 1:2) # specific items in set 1 and set 2

r unite(venn_y, 1:2) # union of set 1 and 2 unite(venn_y, "all") # union of all four sets unite(venn_y, c("A", "B", "C"))

Combined results were provided as VennPlotData object.

r pd = process_data(venn_y) pd

r venn_set(pd)

r venn_region(pd)

Please note in order to keep the result concise, the containing items are nested. You may use the following methods to further process it.

r venn_region(pd) |> tidyr::unnest(item)

r venn_region(pd) |> dplyr::rowwise() |> dplyr::mutate(item = paste0(item, collapse = ", "))

Reference

Some of these above-mentioned functions are originally developed by Turgut Yigit Akyol in RVenn.



gaospecial/ggVennDiagram documentation built on Oct. 24, 2024, 11:40 a.m.