ggVennDiagram help
1
0
Entering edit mode
14 months ago
Dr. • 0

Hi all,

I'm creating Venn's using ggVennDiagram and I can print the intersection tibble using the process_region_data() function but I cannot figure out how to print the components of each intersection (the lists of intersection elements)? Can anyone help me here? Ultimately I want to extract these to a csv.

Cheerio,
B

r ggVennDiagram • 670 views
ADD COMMENT
1
Entering edit mode
14 months ago
Basti ★ 2.0k

Hi, it is a feature that I also struggled to find a solution so I needed to customize some a code to make it work as I want.

So here is my solution. I have found a very useful code on GitHub : https://github.com/hms-dbmi/UpSetR/issues/85#issuecomment-415480954 I adapted it to make it more readable so here is my final code :

overlapGroups <- function (listInput, sort = TRUE) {
  listInputmat    <- fromList(listInput) == 1
  listInputunique <- unique(listInputmat)
  grouplist <- list()
  for (i in 1:nrow(listInputunique)) {
    currentRow <- listInputunique[i,]
    myelements <- which(apply(listInputmat,1,function(x) all(x == currentRow)))
    attr(myelements, "groups") <- currentRow
    grouplist[[paste(colnames(listInputunique)[currentRow], collapse = ":")]] <- myelements
    myelements
  }
  if (sort) {
    grouplist <- grouplist[order(sapply(grouplist, function(x) length(x)), decreasing = TRUE)]
  }
  attr(grouplist, "elements") <- unique(unlist(listInput))
  return(grouplist)
}

Intersection=overlapGroups(yourlist)
purrr::map(Intersection, ~ attr(Intersection, "elements")[.x] )

Example :

yourlist=list(A=c("a","b","c","d"),B=c("a","c","e","f"))
Intersection=overlapGroups(yourlist)
purrr::map(Intersection, ~ attr(Intersection, "elements")[.x] )
$`A:B`
[1] "a" "c"

$A
[1] "b" "d"

$B
[1] "e" "f"
ADD COMMENT

Login before adding your answer.

Traffic: 2905 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6