| Title: | Venn Diagram |
|---|---|
| Description: | Generate Venn plots, summary tables, and ellipse paths for polygon clipping. Provides direct access to subsets of interest and offers flexible customization of Venn diagrams. Summary tables are also available when Venn diagram visualization is not suitable. |
| Authors: | Joon-Keat Lai [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-9840-5836>) |
| Maintainer: | Joon-Keat Lai <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.3 |
| Built: | 2026-06-01 10:24:44 UTC |
| Source: | https://github.com/p10911004-npust/venny |
Produce a bits matrix for all possible combinations of the input sets.
bits_encoding(x, rownames = TRUE, sep = "")bits_encoding(x, rownames = TRUE, sep = "")
x |
A character vector. |
rownames |
Logical (default: TRUE). Whether to show rownames. |
sep |
A character used to separate the group names (default is |
A numeric matrix with values of 0 or 1.
bits_encoding(c("A", "B", "C", "D"))bits_encoding(c("A", "B", "C", "D"))
This is used to generate the ellipse line color and transparency parameters,
for passing into the venny()s ellipse.line argument.
ellipse_line( linetype = "blank", linewidth = 0.5, color = c("#CC79A7", "#009E73", "#E69F00", "#56B4E9"), alpha = 0.5 ) ellipse_fill( color = c("#CC79A7", "#009E73", "#E69F00", "#56B4E9"), alpha = 0.2 )ellipse_line( linetype = "blank", linewidth = 0.5, color = c("#CC79A7", "#009E73", "#E69F00", "#56B4E9"), alpha = 0.5 ) ellipse_fill( color = c("#CC79A7", "#009E73", "#E69F00", "#56B4E9"), alpha = 0.2 )
linetype |
A character. The options are: blank, solid, dashed, dotted, dotdash, longdash, twodash. |
linewidth |
A number (default: 0.5). |
color |
A character vector (default: |
alpha |
A number range from 0 to 1 (default: 0.5). Set the line transparency. |
A list contains "color" and "alpha" values.
ellipse_line()ellipse_line()
This is an internal function used to generate the ellipse parameters that
was used by the generate_ellipse_path() function.
It returns a list encompassing 3 lists.
Each list consists of the x0, y0, long-arm, short-arm, and angle default values
for generating 2, 3, or 4 ellipses.
ellipse_position()ellipse_position()
A two-layer nested list.
ellipse_position()ellipse_position()
Create a desired length of vector by trimming/extending the x vector.
fixed_length(x, len, fill_with = NULL)fixed_length(x, len, fill_with = NULL)
x |
A vector. |
len |
Desired length. |
fill_with |
Element used to extend the vector length.
If set to |
A vector
# Extend `x` to fulfill the `len` requirement fixed_length(1:5, 7) # Trim `x` to fulfill the `len` requirement fixed_length(1:5, 3)# Extend `x` to fulfill the `len` requirement fixed_length(1:5, 7) # Trim `x` to fulfill the `len` requirement fixed_length(1:5, 3)
Generate Ellipse Path
generate_ellipse_path(x0 = 0, y0 = 0, a = 2, b = 1, angle = 0, density = 200)generate_ellipse_path(x0 = 0, y0 = 0, a = 2, b = 1, angle = 0, density = 200)
x0 |
The coordinate x of the polygon center point (default: 0). |
y0 |
The coordinate y of the polygon center point (default: 0). |
a |
Long arm (default: 2). |
b |
Short arm (default: 1). |
angle |
Rotation angle in degree (default: 0). |
density |
Greater amount of points yield smoother ellipse (default: 200). |
A data.frame with the point coordinates (x, y) to construct the polygon
library(ggplot2) # Draw a circle circle <- generate_ellipse_path(a = 1, b = 1) ggplot(circle, aes(x, y)) + geom_polygon() + coord_fixed() # Draw an ellipse ellipse <- generate_ellipse_path(a = 2, b = 1, angle = 45) ggplot(ellipse, aes(x, y)) + geom_polygon() + coord_fixed()library(ggplot2) # Draw a circle circle <- generate_ellipse_path(a = 1, b = 1) ggplot(circle, aes(x, y)) + geom_polygon() + coord_fixed() # Draw an ellipse ellipse <- generate_ellipse_path(a = 2, b = 1, angle = 45) ggplot(ellipse, aes(x, y)) + geom_polygon() + coord_fixed()
A handy wrapper for the ggplot2::geom_polygon() used to represent the
result of set operations.
highlight( venn, setops, color = "black", linewidth = 1.2, linetype = "solid", fill = "black", alpha = 0.2, ... )highlight( venn, setops, color = "black", linewidth = 1.2, linetype = "solid", fill = "black", alpha = 0.2, ... )
venn |
Venn diagram produced from |
setops |
The result of set operations. |
color |
Character (default: "transparent"). The polygon line color. |
linewidth |
Numeric (default: 1.5). The polygon linewidth. |
linetype |
Character (default: "solid"). The polygon linetype. |
fill |
Character (default: "black"). The polygon color. |
alpha |
Numeric (default: 0.4). The polygon transparency (0-1). |
... |
The other arguments passed into |
A ggplot object.
data <- list( Set_A = c(10:100, 500:600), Set_B = c(5:150, 550:650), Set_C = c(80:180, 580:680), Set_D = c(120:220, 520:620) ) out <- venny(data, detail = TRUE) p0 <- out$venn ep <- out$ellipse_path res <- intersect(ep$Set_A, ep$Set_B, ep$Set_D) highlight(p0, res)data <- list( Set_A = c(10:100, 500:600), Set_B = c(5:150, 550:650), Set_C = c(80:180, 580:680), Set_D = c(120:220, 520:620) ) out <- venny(data, detail = TRUE) p0 <- out$venn ep <- out$ellipse_path res <- intersect(ep$Set_A, ep$Set_B, ep$Set_D) highlight(p0, res)
Calculate the number of combinations that can be derived from the given character vector.
how_many_subsets(x, detail = FALSE)how_many_subsets(x, detail = FALSE)
x |
A character vector. |
detail |
Logical (default: FALSE). Whether to output the combinations. |
An integer value or a list.
how_many_subsets(c("qqa", "bnk", "sdf", "123"))how_many_subsets(c("qqa", "bnk", "sdf", "123"))
A list of essential information for RNA-seq analysis and an example for demonstration.
LGL23LGL23
An object of class list of length 4.
sample_info: the information for the sample IDs noted in the count matrix.
GFD: A data.frame of gene functional description.
count_matrix: A matrix of the gene expression count reads for each sample. The row names are gene IDs; the column names are sample IDs.
DEGs: An example demonstrating differentially expressed genes across four conditions.
This is an internal function for venny() to automatically generate
set labels, when the input list is unnamed.
set_label_default(n_sets) subset_label_default(n_sets)set_label_default(n_sets) subset_label_default(n_sets)
n_sets |
An integer. |
A list.
set_label_default(3)set_label_default(3)
Generate a list of the available set label font parameters.
set_label_font( family = "sans", face = "bold", size = 5, color = c("#CC79A7", "#009E73", "#E69F00", "#56B4E9"), angle = NULL ) subset_label_font( family = "sans", face = "bold.italic", size = 4, color = "black", angle = 0 ) subset_count_font( family = "sans", face = "plain", size = 4, color = "grey20", angle = 0 ) subset_percentage_font( family = "sans", face = "plain", size = 4, color = "grey20", angle = 0 )set_label_font( family = "sans", face = "bold", size = 5, color = c("#CC79A7", "#009E73", "#E69F00", "#56B4E9"), angle = NULL ) subset_label_font( family = "sans", face = "bold.italic", size = 4, color = "black", angle = 0 ) subset_count_font( family = "sans", face = "plain", size = 4, color = "grey20", angle = 0 ) subset_percentage_font( family = "sans", face = "plain", size = 4, color = "grey20", angle = 0 )
family |
Character (default: "sans"). |
face |
Character (default: "bold"). |
size |
Numeric (default: 5). |
color |
Character (default: c("#009E73", "#E69F00", "#CC79A7", "#56B4E9")). |
angle |
Numeric | NULL (default: NULL). |
A list.
set_label_font()set_label_font()
Generate the coordinates for the set labels. This is passed into the venny()'s
set.label.position arguments.
set_label_position(hjust = 0, vjust = 0, show = NULL, hide = NULL) subset_label_position(hjust = 0, vjust = 0, show = NULL, hide = NULL) subset_count_position(hjust = 0, vjust = 0, show = NULL, hide = NULL) subset_percentage_position(hjust = 0, vjust = 0, show = NULL, hide = NULL)set_label_position(hjust = 0, vjust = 0, show = NULL, hide = NULL) subset_label_position(hjust = 0, vjust = 0, show = NULL, hide = NULL) subset_count_position(hjust = 0, vjust = 0, show = NULL, hide = NULL) subset_percentage_position(hjust = 0, vjust = 0, show = NULL, hide = NULL)
hjust |
A numeric vector (default: 0). Horizontal adjustment, adjust the x-axis coordinates of the set labels. |
vjust |
A numeric vector (default: 0). Vertical adjustment, adjust the y-axis coordinates of the set labels. |
show |
A character vector (default: NULL). Show only the specified set labels. By default, show all labels. |
hide |
A character vector (default: NULL). Do not show the specified set labels. By default, show all labels. |
A list contains 3 named list. Each named list contains the x, y coordinates of the set labels for different venn diagram (2, 3, or 4 ellipses), respectively.
set_label_position()set_label_position()
Perform intersection (intersect()), union (union()), and difference (setdiff())
for multiple venny_ep objects representing sets. They are handy wrappers of
the polyclip::polyclip() function.
intersect(x, y, ...) union(x, y, ...) setdiff(x, y, ...) ## S3 method for class 'venny_setops' intersect(x, y, ...) ## S3 method for class 'venny_setops' union(x, y, ...) ## S3 method for class 'venny_setops' setdiff(x, y, ...)intersect(x, y, ...) union(x, y, ...) setdiff(x, y, ...) ## S3 method for class 'venny_setops' intersect(x, y, ...) ## S3 method for class 'venny_setops' union(x, y, ...) ## S3 method for class 'venny_setops' setdiff(x, y, ...)
x |
A two-column matrix consists of the point coordinates (x, y) used to construct the ellipse. This is the reference-ellipse used to be clipped by the others. |
y |
A two-column matrix consists of the point coordinates (x, y) used to construct the ellipse.
This is the object-ellipse used to clip the reference ellipse, i.e. |
... |
The other object-ellipses. |
These functions override the base versions to make them generic so that venny
can provide methods to proceed the venny_ep class object. The default methods
call the base versions.
A list contains one or multiple two-column dataframe. Each dataframe is the point coordinates (x, y) used to construct a polygon.
data <- list( Set_A = c(10:100, 500:600), Set_B = c(5:150, 550:650), Set_C = c(80:180, 580:680), Set_D = c(120:220, 520:620) ) out <- venny(data, detail = TRUE) p0 <- out$venn ep <- out$ellipse_path #------------- Intersection -------------# res <- intersect(ep$Set_A, ep$Set_B, ep$Set_D) highlight(p0, res) #----------------- Union ----------------# res <- union(ep$Set_A, ep$Set_C, ep$Set_D) highlight(p0, res) #--------------- Difference -------------# res <- setdiff(ep$Set_B, ep$Set_D, ep$Set_A, ep$Set_C) highlight(p0, res) #---------- Multiple operations ---------# res <- union(ep$Set_A, ep$Set_B, ep$Set_C) |> intersect(ep$Set_D) |> setdiff(ep$Set_B) highlight(p0, res)data <- list( Set_A = c(10:100, 500:600), Set_B = c(5:150, 550:650), Set_C = c(80:180, 580:680), Set_D = c(120:220, 520:620) ) out <- venny(data, detail = TRUE) p0 <- out$venn ep <- out$ellipse_path #------------- Intersection -------------# res <- intersect(ep$Set_A, ep$Set_B, ep$Set_D) highlight(p0, res) #----------------- Union ----------------# res <- union(ep$Set_A, ep$Set_C, ep$Set_D) highlight(p0, res) #--------------- Difference -------------# res <- setdiff(ep$Set_B, ep$Set_D, ep$Set_A, ep$Set_C) highlight(p0, res) #---------- Multiple operations ---------# res <- union(ep$Set_A, ep$Set_B, ep$Set_C) |> intersect(ep$Set_D) |> setdiff(ep$Set_B) highlight(p0, res)
venny summary data.frameA data.frame consists of each combination of the input sets.
venn_summary(data = list(), show_elements = TRUE)venn_summary(data = list(), show_elements = TRUE)
data |
A named list contains 2 ~ 26 sets of elements.
For example, |
show_elements |
Logical (default: FALSE). List out the elements of each zone in the dataframe. |
A data frame contains necessary information for subsequent inferences and plotting.
venn_summary(LGL23$DEGs)venn_summary(LGL23$DEGs)
Venn diagram
venny( data, detail = FALSE, ellipse.line = ellipse_line(), ellipse.fill = ellipse_fill(), ellipse.density = 200L, set.label = TRUE, set.label.position = set_label_position(), set.label.font = set_label_font(), subset.label = TRUE, subset.label.position = subset_label_position(), subset.label.font = subset_label_font(), subset.count = TRUE, subset.count.position = subset_count_position(), subset.count.font = subset_count_font(), subset.percentage = TRUE, subset.percentage.position = subset_count_position(vjust = -0.3), subset.percentage.font = subset_percentage_font(), subset.percentage.rounding = 1L )venny( data, detail = FALSE, ellipse.line = ellipse_line(), ellipse.fill = ellipse_fill(), ellipse.density = 200L, set.label = TRUE, set.label.position = set_label_position(), set.label.font = set_label_font(), subset.label = TRUE, subset.label.position = subset_label_position(), subset.label.font = subset_label_font(), subset.count = TRUE, subset.count.position = subset_count_position(), subset.count.font = subset_count_font(), subset.percentage = TRUE, subset.percentage.position = subset_count_position(vjust = -0.3), subset.percentage.font = subset_percentage_font(), subset.percentage.rounding = 1L )
data |
A list with 2 to 4 vectors |
detail |
Logical (default: TRUE). If TRUE, output a list contains the venn diagram and summary table. Otherwise, output only venn diagram. |
ellipse.line |
A list. See |
ellipse.fill |
A list. See |
ellipse.density |
An integer (default: 200L). Higher value yield smoother ellipse. |
set.label |
Logical (default: TRUE). If TRUE, show the set labels. |
set.label.position |
A list. See |
set.label.font |
A list. See |
subset.label |
Logical (default: TRUE). If TRUE, show the subset labels.
If a named list is provided, then the selected subset name will be renamed.
For example, |
subset.label.position |
A list. See |
subset.label.font |
A list. See |
subset.count |
Logical (default: TRUE). If TRUE, show the element counts for each subset. |
subset.count.position |
A list. See |
subset.count.font |
A list. See |
subset.percentage |
Logical (default: TRUE). If TRUE, show the percentages of the counts. |
subset.percentage.position |
A list. See |
subset.percentage.font |
A list. See |
subset.percentage.rounding |
An integer (default: 1L). How many decimal points. |
A venn diagram which is a ggplot object.
lst <- LGL23$DEGs setLabelPosition <- set_label_position(hjust = c(0.2, -0.5, 0.5, -0.2)) venny(lst, set.label.position = setLabelPosition)lst <- LGL23$DEGs setLabelPosition <- set_label_position(hjust = c(0.2, -0.5, 0.5, -0.2)) venny(lst, set.label.position = setLabelPosition)