Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

r - How to obtain the list of elements from a Venn diagram

I have a Venn diagram made from 3 lists, I would like to obtain all the different sub-lists, common elements between two lists, between the tree of them, and the unique elements for each list. Is there a way to make this as straight forward as possible?

AW.DL <- c("a","b","c","d")

AW.FL <- c("a","b", "e", "f")

AW.UL <- c("a","c", "e", "g")

venn.diagram(
  x = list(AW.DL, AW.FL, AW.UL),
  category.names = c("AW.DL" , "AW.FL","AW.UL" ),
  filename = '#14_venn_diagramm.png',
  output=TRUE,
  na = "remove"
)
question from:https://stackoverflow.com/questions/65898472/how-to-obtain-the-list-of-elements-from-a-venn-diagram

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found that the package VennDiagram has a function calculate.overlap() but I wasn't able to find a way to name the sections from this function. However, if you use package gplots , there is the function venn() which will return the intersections attribute.

AW.DL <- c("a","b","c","d")

AW.FL <- c("a","b", "e", "f")

AW.UL <- c("a","c", "e", "g")

library(gplots)

lst <- list(AW.DL,AW.FL,AW.UL)

ItemsList <- venn(lst, show.plot = FALSE)

lengths(attributes(ItemsList)$intersections)

Output:

> lengths(attributes(ItemsList)$intersections)
    A     B     C   A:B   A:C   B:C A:B:C 
    1     1     1     1     1     1     1

To get elements, just print attributes(ItemsList)$intersections:

> attributes(ItemsList)$intersections
$A
[1] "d"

$B
[1] "f"

$C
[1] "g"

$`A:B`
[1] "b"

$`A:C`
[1] "c"

$`B:C`
[1] "e"

$`A:B:C`
[1] "a"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...