Movatterモバイル変換


[0]ホーム

URL:


Title:Draw Venn Diagram by 'ggplot2'
Version:0.1.19
Author:Linlin YanORCID iD [aut, cre]
Maintainer:Linlin Yan <yanlinlin82@gmail.com>
Description:An easy-to-use way to draw pretty Venn diagrams using 'ggplot2'. This package provides functions to create Venn diagrams with customizable colors, labels, and styling options.
URL:https://yanlinlin82.github.io/ggvenn/,https://github.com/yanlinlin82/ggvenn
BugReports:https://github.com/yanlinlin82/ggvenn/issues
License:MIT + file LICENSE
Encoding:UTF-8
RoxygenNote:7.3.3
Depends:ggplot2
Suggests:rmarkdown, testthat (≥ 3.0.0)
Imports:dplyr (≥ 1.1.0), grid, rlang, scales (≥ 1.2.0)
Config/testthat/edition:3
NeedsCompilation:no
Packaged:2025-10-08 08:13:47 UTC; yanll
Repository:CRAN
Date/Publication:2025-10-08 13:30:02 UTC

ggvenn: Draw Venn Diagram by 'ggplot2'

Description

An easy-to-use way to draw pretty Venn diagrams using 'ggplot2'. This package provides functions to create Venn diagrams with customizable colors, labels, and styling options.

Author(s)

Maintainer: Linlin Yanyanlinlin82@gmail.com (ORCID)

See Also

Useful links:


Utility functions for data type conversion between data.frame and list.

Description

Utility functions for data type conversion between data.frame and list.

Usage

data_frame_to_list(x)list_to_data_frame(x)

Arguments

x

A data.frame with logical columns representing sets, or a list of sets.

Value

A list of sets or a data.frame with logical columns representing sets.

Examples

# Convert data.frame to listd <- 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)# Convert list to data.framea <- list(A = 1:5, B = 4:6)print(a)list_to_data_frame(a)# Round-trip conversionidentical(a, data_frame_to_list(list_to_data_frame(a)))  # TRUEidentical(d, list_to_data_frame(data_frame_to_list(d)))  # TRUE

Plot venn diagram as a ggplot layer object. It supports only data frame as input.

Description

Plot venn diagram as a ggplot layer object. It supports only data frame as input.

Usage

geom_venn(  mapping = NULL,  data = NULL,  stat = "identity",  position = "identity",  ...,  set_names = NULL,  element_column = NULL,  show_elements = FALSE,  show_set_totals = "none",  show_stats = c("cp", "c", "p"),  show_counts = TRUE,  show_percentage = TRUE,  digits = 1,  label_sep = ",",  count_column = NULL,  show_outside = c("auto", "none", "always"),  auto_scale = FALSE,  fill_color = default_color_list,  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,  comma_sep = FALSE,  padding = 0.2,  max_elements = 6,  text_truncate = TRUE)

Arguments

mapping

Set of aesthetic mappings created byaes(). If specified andinherit.aes = TRUE (the default), it is combined with the default mappingat the top level of the plot. You must supplymapping if there is no plotmapping.

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. Thiscan be used in various ways, including to prevent overplotting andimproving the display. Theposition argument accepts the following:

  • The result of calling a position function, such asposition_jitter().This method allows for passing extra arguments to the position.

  • A string naming the position adjustment. To give the position as astring, strip the function name of theposition_ prefix. For example,to useposition_jitter(), give the position as"jitter".

  • For more information and other ways to specify the position, see thelayer position documentation.

...

Other arguments passed on tolayer()'sparams argument. Thesearguments broadly fall into one of 4 categories below. Notably, furtherarguments to theposition argument, or aesthetics that are requiredcannot be passed through.... Unknown arguments that are not partof the 4 categories below are ignored.

  • Static aesthetics that are not mapped to a scale, but are at a fixedvalue and apply to the layer as a whole. For example,colour = "red"orlinewidth = 3. The geom's documentation has anAestheticssection that lists the available options. The 'required' aestheticscannot be passed on to theparams. Please note that while passingunmapped aesthetics as vectors is technically possible, the order andrequired length is not guaranteed to be parallel to the input data.

  • When constructing a layer usinga⁠stat_*()⁠ function, the... argument can be used to pass onparameters to thegeom part of the layer. An example of this isstat_density(geom = "area", outline.type = "both"). The geom'sdocumentation lists which parameters it can accept.

  • Inversely, when constructing a layer using a⁠geom_*()⁠ function, the... argument can be used to pass on parametersto thestat part of the layer. An example of this isgeom_area(stat = "density", adjust = 0.5). The stat's documentationlists which parameters it can accept.

  • Thekey_glyph argument oflayer() may also be passed on through.... This can be one of the functions described askey glyphs, to change the display of the layer in the legend.

set_names

Set names, use column names if omitted.

element_column

A single character value use as column name to select 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.Pass a string like "cp" to show both.

show_counts

Show count for each set.

show_percentage

Show percentage for each set.

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). Options: "auto", "none", "always".

auto_scale

Allow automatically resizing circles according to element counts (only for 2-set diagrams).

fill_color

Filling colors in circles. Can be a single color or a vector of colors for each set.

fill_alpha

Transparency for filling circles. Can be a single value or a vector for each set.

stroke_color

Stroke color for drawing circles. Can be a single color or a vector of colors for each set.

stroke_alpha

Transparency for drawing circles. Can be a single value or a vector for each set.

stroke_size

Stroke size for drawing circles. Can be a single value or a vector for each set.

stroke_linetype

Line type for drawing circles. Can be a single value or a vector for each set.

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.

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.

max_elements

Maximum number of elements to display when show_elements=TRUE.

text_truncate

Whether to truncate text when elements exceed max_elements.

Value

A ggplot layer object to add to a ggplot.

See Also

ggvenn

Examples

library(ggvenn)# use data.frame as inputd <- 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 grammaggplot(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 colorggplot(d) +  geom_venn(aes(A = `Set 1`, B = `Set 2`), fill_color = c("red", "blue")) +  coord_fixed() +  theme_void()# hide percentageggplot(d) +  geom_venn(aes(A = `Set 1`, B = `Set 2`), show_stats = "c") +  coord_fixed() +  theme_void()# change precision of percentagesggplot(d) +  geom_venn(aes(A = `Set 1`, B = `Set 2`), digits = 2) +  coord_fixed() +  theme_void()# show elements instead of count/percentageggplot(d) +  geom_venn(aes(A = `Set 1`, B = `Set 2`, C = `Set 3`, D = `Set 4`, label = value)) +  coord_fixed() +  theme_void()

Extract Venn diagram data table from ggvenn plot

Description

Extract Venn diagram data table from ggvenn plot

Usage

get_venn_table(g)

Arguments

g

A ggplot object created by ggvenn()

Value

A data frame containing the Venn diagram intersection data

Examples

library(ggvenn)g <- ggvenn(list(A = 1:5, B = 4:9, C = c(2:3, 8:12), D = c(1, 5, 9)))get_venn_table(g)

Plot venn diagram as an independent function. It supports both data frame and list as input.

Description

Plot venn diagram as an independent function. It supports both data frame and list as input.

Usage

ggvenn(  data,  columns = NULL,  element_column = NULL,  show_elements = FALSE,  show_set_totals = "none",  show_stats = c("cp", "c", "p"),  show_counts = TRUE,  show_percentage = TRUE,  digits = 1,  label_sep = ",",  count_column = NULL,  show_outside = c("auto", "none", "always"),  auto_scale = FALSE,  fill_color = default_color_list,  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,  comma_sep = FALSE,  padding = 0.2,  max_elements = 6,  text_truncate = TRUE)

Arguments

data

A data.frame or a list as input data.

columns

A character vector use as index to select columns/elements.

element_column

A single character value use as column name to select elements.It is only allowed when data is a data.frame.

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.Pass a string like "cp" to show both. Any other string like "none" to hide both.

show_counts

Show count for each set.

show_percentage

Show percentage for each set.

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). Options: "auto", "none", "always".

auto_scale

Allow automatically resizing circles according to element counts (only for 2-set diagrams).

fill_color

Filling colors in circles. Can be a single color or a vector of colors for each set.

fill_alpha

Transparency for filling circles. Can be a single value or a vector for each set.

stroke_color

Stroke color for drawing circles. Can be a single color or a vector of colors for each set.

stroke_alpha

Transparency for drawing circles. Can be a single value or a vector for each set.

stroke_size

Stroke size for drawing circles. Can be a single value or a vector for each set.

stroke_linetype

Line type for drawing circles. Can be a single value or a vector for each set.

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.

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.

max_elements

Maximum number of elements to display when show_elements=TRUE.

text_truncate

Whether to truncate text when elements exceed max_elements.

Value

The ggplot object to print or save to file.

See Also

geom_venn

Examples

library(ggvenn)# use list as inputa <- list(A = 1:5, B = 4:9, C = c(2:3, 8:12), D = c(1, 5, 9))ggvenn(a, c("A", "B"))ggvenn(a, c("A", "B", "C"))ggvenn(a)# use data.frame as inputd <- 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 colorggvenn(d, c("Set 1", "Set 2"), fill_color = c("red", "blue"))# hide percentageggvenn(d, c("Set 1", "Set 2"), show_stats = "c")# change precision of percentagesggvenn(d, c("Set 1", "Set 2"), digits = 2)# show elements instead of count/percentageggvenn(a, show_elements = TRUE)ggvenn(d, show_elements = TRUE, element_column = "value")

[8]ページ先頭

©2009-2025 Movatter.jp