Chapter 2 Introduction
Suppose we have a list of genes.
<- paste0("gene",1:1000) genes set.seed(20210302) <- list(A = sample(genes,100), gene_list B = sample(genes,200), C = sample(genes,300), D = sample(genes,200)) library(dplyr)
VennDiagram (Chen 2018) is currently the most popular Venn plot tool in R environment.
library(VennDiagram) <- venn.diagram(x = gene_list, filename = NULL) VennDiagram ::plot_grid(VennDiagram)cowplot
It provide basic functions to draw Euler plot.
<- draw.triple.venn( venn.plot area1 = 65, area2 = 75, area3 = 85, n12 = 35, n23 = 15, n13 = 25, n123 = 5, category = c("First", "Second", "Third"), fill = c("blue", "red", "green"), lty = "blank", cex = 2, cat.cex = 2, cat.col = c("blue", "red", "green"), euler.d = TRUE )
helper function to get Venn partitions.
get.venn.partitions(gene_list) %>% dplyr::as_tibble()
## # A tibble: 15 x 7 ## A B C D ..set.. ..values.. ..count.. ## <lgl> <lgl> <lgl> <lgl> <chr> <named list> <int> ## 1 TRUE TRUE TRUE TRUE A∩B∩C∩D <chr > 1 ## 2 FALSE TRUE TRUE TRUE (B∩C∩D)<U+2216>(A) <chr > 7 ## 3 TRUE FALSE TRUE TRUE (A∩C∩D)<U+2216>(B) <chr > 2 ## 4 FALSE FALSE TRUE TRUE (C∩D)<U+2216>(A∪B) <chr > 41 ## 5 TRUE TRUE FALSE TRUE (A∩B∩D)<U+2216>(C) <chr > 5 ## 6 FALSE TRUE FALSE TRUE (B∩D)<U+2216>(A∪C) <chr > 25 ## 7 TRUE FALSE FALSE TRUE (A∩D)<U+2216>(B∪C) <chr > 12 ## 8 FALSE FALSE FALSE TRUE (D)<U+2216>(A∪B∪C) <chr > 107 ## 9 TRUE TRUE TRUE FALSE (A∩B∩C)<U+2216>(D) <chr > 5 ## 10 FALSE TRUE TRUE FALSE (B∩C)<U+2216>(A∪D) <chr > 48 ## 11 TRUE FALSE TRUE FALSE (A∩C)<U+2216>(B∪D) <chr > 22 ## 12 FALSE FALSE TRUE FALSE (C)<U+2216>(A∪B∪D) <chr > 174 ## 13 TRUE TRUE FALSE FALSE (A∩B)<U+2216>(C∪D) <chr > 10 ## 14 FALSE TRUE FALSE FALSE (B)<U+2216>(A∪C∪D) <chr > 99 ## 15 TRUE FALSE FALSE FALSE (A)<U+2216>(B∪C∪D) <chr > 43
This package can specify the filled color for each region, but the first required parameter is a numeric vector of length 15, with specific names in suitable order, which makes it is very complicated to setup and use.
Besides, the filled color need to be specified one by one, which is very complicated as well.
library(colorfulVennPlot) <- c('red', 'yellow', 'green', 'pink', 'darkgreen','blue','lightblue','tan', Colors 'yellowgreen','orange','purple','white','grey','plum','brown') <- seq(15) regions names(regions) <- c('1000', '0100', '1100', '0010', '1010', '0110', '1110', '0001', '1001', '0101', '1101', '0011', '1011', '0111', '1111') plotVenn4d(regions, Colors=Colors)
venn is very simple.
venn also support different shapes.
venn(x = gene_list, ellipse = TRUE)
ggplot, but it depends on
ggpolypath, which is not popular.
::venn(gene_list, ellipse = TRUE, ggplot = TRUE)venn
venn plots Venn diagram up to 7 sets.
venn accepts multiple format of input.
<- c('~A~B~C~D', '~A~B~CD', '~A~BC~D', '~A~BCD', '~AB~C~D', '~AB~CD', '~ABC~D', '~ABCD', 'A~B~C~D', 'A~B~CD', 'A~BC~D', 'A~BCD', 'AB~C~D', 'AB~CD', 'ABC~D', 'ABCD') intersections venn(intersections, zcol = colors()[sample(1:657, 16)])
venn("A*D, A*B*~C + B*C*~D", zcol = c("blue", "red"))
venn("AD, AB~C + BC~D", zcol = c("blue", "red")) venn("1-----")
venn("100 + 110 + 101 + 111")
nVennR provides an interface for the
nVenn algorithm (Pérez-Silva, Araujo-Voces, and Quesada 2018). This algorithm works for any number of sets, and usually yields pleasing and informative Venn diagrams with proportionality information.
library(nVennR) <- plotVenn(gene_list)myNV
eulerr generates area-proportional euler diagrams that display set relationships (intersections, unions, and disjoints) with circles or ellipses.
Unlike Venn diagrams, which show all possible relations between different sets, the Euler diagram shows only relevant relationships.
Venn diagrams are a more restrictive form of Euler diagrams. A Venn diagram must contain all \(2^n\) logically possible zones of overlap between its \(n\) curves, representing all combinations of inclusion/exclusion of its constituent sets.
## Warning: package 'eulerr' was built under R version 4.1.1
<- venn(gene_list) venn_plot plot(venn_plot)
<- euler(gene_list) euler_plot plot(euler_plot)
At the time of March 9th, 2021, it is possible to provide input to eulerr as either
a named numeric vector with set combinations as disjoint set combinations or unions (depending on how the argument type is set in euler()), a matrix or data frame of logicals with columns representing sets and rows the set relationships for each observation, a list of sample spaces, or a table.
# Input as a matrix of logicals set.seed(1) <- cbind( mat A = sample(c(TRUE, TRUE, FALSE), 50, TRUE), B = sample(c(TRUE, FALSE), 50, TRUE), C = sample(c(TRUE, FALSE, FALSE, FALSE), 50, TRUE) )<- euler(mat))(fit2
## original fitted residuals regionError ## A 13 13 0 0.008 ## B 4 4 0 0.002 ## C 0 0 0 0.000 ## A&B 17 17 0 0.010 ## A&C 5 5 0 0.003 ## B&C 1 0 1 0.024 ## A&B&C 2 2 0 0.001 ## ## diagError: 0.024 ## stress: 0.002
The diagnose function is good.
venneulerr depends on JAVA runtime environment, which makes its installation is unbearable for non-JAVA users.
Besides, it only has one exported function, which doesn’t support list input.
## Warning: package 'rJava' was built under R version 4.1.1
<- c(A=0.3, B=0.3, C=1.1, "A&B"=0.1, "A&C"=0.2, "B&C"=0.1 ,"A&B&C"=0.1,"D"=0.2,"C&D"=0.1) combinations <- venneuler(combinations) vd plot(vd)
RVenn is a package for dealing with multiple sets, while the base R functions (
setdiff) only work with two sets.
The functions overlap, unite and discern abstract away the details, so one can just construct the universe and choose the sets to operate by index or set name.
RVenn provide a
ggvenn() function to draw 2-3 sets Venn diagram. In this case,
its advantages are mostly rely on set operation functions.
gplots provides various R programming tools for plotting data. It supports Venn plot up to five sets.
## Warning: package 'ggVennDiagram' was built under R version 4.1.1
ggvenn can show elements in polygon regions.
<- list(A = c("apple", "pear", "peach"), a B = c("apple", "lemon")) ggvenn(a, show_elements = TRUE)
ggvenn(a, show_elements = TRUE, label_sep = "\n") # show elements in line