Title: | Draw Venn Diagram by 'ggplot2' |
---|---|
Description: | An easy-to-use way to draw pretty venn diagram by 'ggplot2'. |
Authors: | Linlin Yan [aut, cre] |
Maintainer: | Linlin Yan <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.16 |
Built: | 2025-03-05 02:46:12 UTC |
Source: | https://github.com/yanlinlin82/ggvenn |
Utility function for data type conversion.
data_frame_to_list(x)
data_frame_to_list(x)
x |
A data.frame with logical columns representing sets. |
A list of sets.
d <- dplyr::tibble(name = 1:6, A = c(rep(TRUE, 5), FALSE), B = rep(c(FALSE, TRUE), each = 3)) print(d) data_frame_to_list(d)
d <- dplyr::tibble(name = 1:6, A = c(rep(TRUE, 5), FALSE), B = rep(c(FALSE, TRUE), each = 3)) print(d) data_frame_to_list(d)
Plot venn diagram as a ggplot layer object. It supports only data frame as input.
geom_venn( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., set_names = NULL, show_set_totals = "none", show_stats = "cp", show_percentage = deprecated(), digits = 1, label_sep = ",", count_column = NULL, show_outside = c("auto", "none", "always"), auto_scale = FALSE, fill_color = c("blue", "yellow", "green", "red"), fill_alpha = 0.5, stroke_color = "black", stroke_alpha = 1, stroke_size = 1, stroke_linetype = "solid", set_name_color = "black", set_name_size = 6, text_color = "black", text_size = 4 )
geom_venn( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., set_names = NULL, show_set_totals = "none", show_stats = "cp", show_percentage = deprecated(), digits = 1, label_sep = ",", count_column = NULL, show_outside = c("auto", "none", "always"), auto_scale = FALSE, fill_color = c("blue", "yellow", "green", "red"), fill_alpha = 0.5, stroke_color = "black", stroke_alpha = 1, stroke_size = 1, stroke_linetype = "solid", set_name_color = "black", set_name_size = 6, text_color = "black", text_size = 4 )
mapping |
Set of aesthetic mappings created by |
data |
A data.frame or a list as input data. |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
set_names |
Set names, use column names if omitted. |
show_set_totals |
Show total count (c) and/or percentage (p) for each set. Pass a string like "cp" to show both. Any other string like "none" to hide both. |
show_stats |
Show count (c) and/or percentage (p) for each set. Pass a string like "cp" to show both. |
show_percentage |
Show percentage for each set. Deprecated, use show_stats instead. |
digits |
The desired number of digits after the decimal point |
label_sep |
separator character for displaying elements. |
count_column |
Specify column for element repeat count. |
show_outside |
Show outside elements (not belongs to any set). |
auto_scale |
Allow automatically resizing circles according to element counts. |
fill_color |
Filling colors in circles. |
fill_alpha |
Transparency for filling circles. |
stroke_color |
Stroke color for drawing circles. |
stroke_alpha |
Transparency for drawing circles. |
stroke_size |
Stroke size for drawing circles. |
stroke_linetype |
Line type for drawing circles. |
set_name_color |
Text color for set names. |
set_name_size |
Text size for set names. |
text_color |
Text color for intersect contents. |
text_size |
Text size for intersect contents. |
The ggplot object to print or save to file.
ggvenn
library(ggvenn) # use data.frame as input d <- dplyr::tibble(value = c(1, 2, 3, 5, 6, 7, 8, 9), `Set 1` = c(TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE), `Set 2` = c(TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE), `Set 3` = c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE), `Set 4` = c(FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE)) # ggplot gramma ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`)) + coord_fixed() + theme_void() ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`, C = `Set 3`)) + coord_fixed() + theme_void() ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`, C = `Set 3`, D = `Set 4`)) + coord_fixed() + theme_void() # set fill color ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`), fill_color = c("red", "blue")) + coord_fixed() + theme_void() # hide percentage ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`), show_stats = 'c') + coord_fixed() + theme_void() # change precision of percentages ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`), digits = 2) + coord_fixed() + theme_void() # show elements instead of count/percentage ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`, C = `Set 3`, D = `Set 4`, label = value)) + coord_fixed() + theme_void()
library(ggvenn) # use data.frame as input d <- dplyr::tibble(value = c(1, 2, 3, 5, 6, 7, 8, 9), `Set 1` = c(TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE), `Set 2` = c(TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE), `Set 3` = c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE), `Set 4` = c(FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE)) # ggplot gramma ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`)) + coord_fixed() + theme_void() ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`, C = `Set 3`)) + coord_fixed() + theme_void() ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`, C = `Set 3`, D = `Set 4`)) + coord_fixed() + theme_void() # set fill color ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`), fill_color = c("red", "blue")) + coord_fixed() + theme_void() # hide percentage ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`), show_stats = 'c') + coord_fixed() + theme_void() # change precision of percentages ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`), digits = 2) + coord_fixed() + theme_void() # show elements instead of count/percentage ggplot(d) + geom_venn(aes(A = `Set 1`, B = `Set 2`, C = `Set 3`, D = `Set 4`, label = value)) + coord_fixed() + theme_void()
Plot venn diagram as an independent function. It supports both data frame and list as input.
ggvenn( data, columns = NULL, show_elements = FALSE, show_set_totals = "none", show_stats = "cp", show_percentage = lifecycle::deprecated(), digits = 1, fill_color = c("blue", "yellow", "green", "red"), fill_alpha = 0.5, stroke_color = "black", stroke_alpha = 1, stroke_size = 1, stroke_linetype = "solid", set_name_color = "black", set_name_size = 6, text_color = "black", text_size = 4, label_sep = ",", count_column = NULL, show_outside = c("auto", "none", "always"), auto_scale = FALSE, comma_sep = FALSE, padding = 0.2 )
ggvenn( data, columns = NULL, show_elements = FALSE, show_set_totals = "none", show_stats = "cp", show_percentage = lifecycle::deprecated(), digits = 1, fill_color = c("blue", "yellow", "green", "red"), fill_alpha = 0.5, stroke_color = "black", stroke_alpha = 1, stroke_size = 1, stroke_linetype = "solid", set_name_color = "black", set_name_size = 6, text_color = "black", text_size = 4, label_sep = ",", count_column = NULL, show_outside = c("auto", "none", "always"), auto_scale = FALSE, comma_sep = FALSE, padding = 0.2 )
data |
A data.frame or a list as input data. |
columns |
A character vector use as index to select columns/elements. |
show_elements |
Show set elements instead of count/percentage. |
show_set_totals |
Show total count (c) and/or percentage (p) for each set. Pass a string like "cp" to show both. Any other string like "none" to hide both. |
show_stats |
Show count (c) and/or percentage (p) for each set. |
show_percentage |
Show percentage for each set. Deprecated, use show_stats instead. Pass a string like "cp" to show both. Any other string like "none" to hide both. |
digits |
The desired number of digits after the decimal point |
fill_color |
Filling colors in circles. |
fill_alpha |
Transparency for filling circles. |
stroke_color |
Stroke color for drawing circles. |
stroke_alpha |
Transparency for drawing circles. |
stroke_size |
Stroke size for drawing circles. |
stroke_linetype |
Line type for drawing circles. |
set_name_color |
Text color for set names. |
set_name_size |
Text size for set names. |
text_color |
Text color for intersect contents. |
text_size |
Text size for intersect contents. |
label_sep |
Separator character for displaying elements. |
count_column |
Specify column for element repeat count. |
show_outside |
Show outside elements (not belongs to any set). |
auto_scale |
Allow automatically resizing circles according to element counts. |
comma_sep |
Whether to use comma as separator for displaying numbers. |
padding |
Padding for the plot. Change this to allow longer labels to be displayed. |
The ggplot object to print or save to file.
geom_venn
library(ggvenn) # use list as input a <- list(`Set 1` = c(1, 3, 5, 7), `Set 2` = c(1, 5, 9), `Set 3` = c(1, 2, 8), `Set 4` = c(6, 7)) ggvenn(a, c("Set 1", "Set 2")) ggvenn(a, c("Set 1", "Set 2", "Set 3")) ggvenn(a) # use data.frame as input d <- dplyr::tibble(value = c(1, 2, 3, 5, 6, 7, 8, 9), `Set 1` = c(TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE), `Set 2` = c(TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE), `Set 3` = c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE), `Set 4` = c(FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE)) ggvenn(d, c("Set 1", "Set 2")) ggvenn(d, c("Set 1", "Set 2", "Set 3")) ggvenn(d) # set fill color ggvenn(d, c("Set 1", "Set 2"), fill_color = c("red", "blue")) # hide percentage ggvenn(d, c("Set 1", "Set 2"), show_stats = 'c') # change precision of percentages ggvenn(d, c("Set 1", "Set 2"), digits = 2) # show elements instead of count/percentage ggvenn(a, show_elements = TRUE) ggvenn(d, show_elements = "value")
library(ggvenn) # use list as input a <- list(`Set 1` = c(1, 3, 5, 7), `Set 2` = c(1, 5, 9), `Set 3` = c(1, 2, 8), `Set 4` = c(6, 7)) ggvenn(a, c("Set 1", "Set 2")) ggvenn(a, c("Set 1", "Set 2", "Set 3")) ggvenn(a) # use data.frame as input d <- dplyr::tibble(value = c(1, 2, 3, 5, 6, 7, 8, 9), `Set 1` = c(TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE), `Set 2` = c(TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE), `Set 3` = c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE), `Set 4` = c(FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE)) ggvenn(d, c("Set 1", "Set 2")) ggvenn(d, c("Set 1", "Set 2", "Set 3")) ggvenn(d) # set fill color ggvenn(d, c("Set 1", "Set 2"), fill_color = c("red", "blue")) # hide percentage ggvenn(d, c("Set 1", "Set 2"), show_stats = 'c') # change precision of percentages ggvenn(d, c("Set 1", "Set 2"), digits = 2) # show elements instead of count/percentage ggvenn(a, show_elements = TRUE) ggvenn(d, show_elements = "value")
Utility function for data type conversion.
list_to_data_frame(x)
list_to_data_frame(x)
x |
A list of sets. |
A data.frame with logical columns representing sets.
a <- list(A = 1:5, B = 4:6) print(a) list_to_data_frame(a)
a <- list(A = 1:5, B = 4:6) print(a) list_to_data_frame(a)