MyNixOS website logo
Description

Draw Venn Diagram by 'ggplot2'.

An easy-to-use way to draw pretty venn diagram by 'ggplot2'.

ggvenn

Venn Diagram by ggplot2, with really easy-to-use API. This package is inspired by Venny

Screenshots

Venn 2Venn 3Venn 4

Installation

install.packages("ggvenn") # install via CRAN

or

if (!require(devtools)) install.packages("devtools")
devtools::install_github("yanlinlin82/ggvenn") # install via GitHub (for latest version)

Quick Start

This package supports both list and data.frame type data as input.

For list data (each element is a set):

library(ggvenn)

a <- list(`Set 1` = c(1, 3, 5, 7, 9),
          `Set 2` = c(1, 5, 9, 13),
          `Set 3` = c(1, 2, 8, 9),
          `Set 4` = c(6, 7, 10, 12))
ggvenn(a, c("Set 1", "Set 2"))            # draw two-set venn
ggvenn(a, c("Set 1", "Set 2", "Set 3"))   # draw three-set venn
ggvenn(a)   # without set names, the first 4 elements in list will be chose to draw four-set venn

For data.frame data (each logical column is a set):

d <- 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"))           # draw two-set venn
ggvenn(d, c("Set 1", "Set 2", "Set 3"))  # draw three-set venn
ggvenn(d)   # without set names, the first 4 logical column in data.frame will be chose to draw four-set venn

For data.frame data, there is also another way to plot in ggplot grammar:

# draw two-set venn (use A, B in aes)
ggplot(d, aes(A = `Set 1`, B = `Set 2`)) +
  geom_venn() + theme_void() + coord_fixed()

# draw three-set venn (use A, B, C in aes)
ggplot(d, aes(A = `Set 1`, B = `Set 2`, C = `Set 3`)) +
  geom_venn() + theme_void() + coord_fixed()

# draw four-set venn (use A, B, C, D in aes)
ggplot(d, aes(A = `Set 1`, B = `Set 2`, C = `Set 3`, D = `Set 4`)) +
  geom_venn() + theme_void() + coord_fixed()

More Options

There are more options for customizing the venn diagram.

  1. Tune the color and size

    For filling:

    • fill_color - default is c("blue", "yellow", "green", "red")
    • fill_alpha - default is 0.5

    For stroke:

    • stroke_color - default is "black"
    • stroke_alpha - default is 1
    • stroke_size - default is 1
    • stroke_linetype - default is "solid"

    For set name:

    • set_name_color - default is "black"
    • set_name_size - default is 6

    For text:

    • text_color - default is "black"
    • text_size - default is 4

    All parameters above could be used in both ggvenn() and geom_venn().

    For example:

    a <- list(A = 1:4, B = c(1,3,5))
    ggvenn(a, stroke_linetype = 2, stroke_size = 0.5,
      set_name_color = "red", set_name_size = 15,
      fill_color = c("pink", "gold"))
    
  2. Show elements

    • show_elements - default is FALSE
    • label_sep - text used to concatenate elements, default is ","

    For example:

    a <- list(A = c("apple", "pear", "peach"),
              B = c("apple", "lemon"))
    ggvenn(a, show_elements = TRUE)
    
    ggvenn(a, show_elements = TRUE, label_sep = "\n")  # show elements in line
    
  3. Hide percentage

    • show_percentage - default is TRUE

    For example:

    a <- list(A = 1:5, B = 1:2)
    ggvenn(a, show_percentage = FALSE)
    
  4. Change digits of percentage

    • digits - default is 1

    For example:

    a <- list(A = 1:5, B = 1:2)
    ggvenn(a, digits = 2)
    

Data Format

The ggvenn support two types of input data: list and data.frame. Two functions (data_frame_to_list() and list_to_data_frame()) can convert data between the two types.

a <- list(A = 1:5, B = 4:6)
d <- tibble(key = 1:6,
            A = c(rep(TRUE, 5), FALSE),
            B = rep(c(FALSE, TRUE), each = 3))

identical(a, data_frame_to_list(d))  # TRUE
identical(d, list_to_data_frame(a))  # TRUE
Metadata

Version

0.1.10

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows