R/regions.R

Defines functions get_region_ids get_region_names get_region_items matrix2list combinations

Documented in combinations

# region items and polygons

#' all possible combinations of n sets
#'
#' @param n dim
#'
#' @importFrom utils combn
combinations <- function(n){
  l <- lapply(seq_len(n), function(x){
    m <- combn(n,x)
    matrix2list(m)
  })
  unlist(l, recursive = F)
}

matrix2list <- function(matrix){
  lapply(seq_len(ncol(matrix)), function(i) matrix[,i])
}

get_region_items <- function(venn){
  n = length(venn@sets)
  c = combinations(n)
  lapply(c, function(i) discern_overlap(venn,i))
}

get_region_names <- function(venn){
  n = length(venn@sets)
  set_name = venn@names
  c = combinations(n)
  sapply(c, function(i) paste0(set_name[i], collapse = ".."))
}

get_region_ids <- function(venn){
  n = length(venn@sets)
  c = combinations(n)
  sapply(c, function(i) paste0(i, collapse = ""))
}

Try the ggVennDiagram package in your browser

Any scripts or data that you put into this service are public.

ggVennDiagram documentation built on Aug. 14, 2023, 5:09 p.m.