knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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
venn_set()
: get set data from the object. r
venn_set(pd)
venn_region()
: get subsets data from the object.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 = ", "))
Some of these above-mentioned functions are originally developed by Turgut Yigit Akyol in RVenn
.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.