Skip to main content
v2026.11,986 entries · CC-BY 4.0

Venn Diagram in R: VennDiagram, ggVennDiagram and ggvenn

How to draw a Venn diagram in R with VennDiagram (venn.diagram), ggVennDiagram and ggvenn, with the code, outputs and common errors.

Written and maintained by CASRAI Editorial Board

Published

On this page

Researchers searching for a Venn diagram in R usually have two or more lists of identifiers (genes, participants, publications, keywords) and want to see which items are shared and which are unique. R has three widely used CRAN packages for this: VennDiagram (function venn.diagram), ggVennDiagram and ggvenn. This guide shows the working pattern for each, how to read the output, and how to get the actual shared members behind the numbers on the plot.

Short answer: put each set in a named list, then call ggVennDiagram(x) for a ggplot2 object (2 to 7 sets), or venn.diagram(x, filename = NULL) followed by grid::grid.draw() for the VennDiagram package.

What a Venn diagram in R is used for in research

A Venn diagram shows the overlap between sets. In research workflows the typical inputs are lists of gene identifiers from different analyses, lists of records returned by different database searches, or participant IDs that satisfy different criteria. For a non-code way to draw one, see the guide on how to make a Venn diagram.

Which package is which: venndiagram r, r venndiagram and venn.diagram r package

All of these searches refer to the same CRAN package, VennDiagram, whose main function is venn.diagram(). Note the capitalisation: the package is VennDiagram, the function is venn.diagram. The package description on CRAN reads “A set of functions to generate high-resolution Venn and Euler plots.”

Install or access (CRAN only)

All three packages are published on CRAN, R’s official package repository. Install from within R:

install.packages("VennDiagram")
install.packages("ggVennDiagram")
install.packages("ggvenn")

The ggVennDiagram README also documents a development version: devtools::install_github("gaospecial/ggVennDiagram"). If installation fails, see how to install libraries in R.

Package CRAN version (date) What CRAN says Depends
VennDiagram 1.8.2 (2026-01-11) Venn and Euler plots R >= 3.5.0, grid, futile.logger
ggVennDiagram 1.5.7 (2026-01-10) 2-7 sets Venn or upset plot; built on ggplot2 R >= 4.1.0
ggvenn 0.1.19 (2025-10-08) Easy way to draw Venn diagrams with ggplot2 ggplot2

Versions and dates are as listed on each package’s CRAN page, checked 2026-11-07.

Step by step: draw a Venn diagram in R

Step 1. Put each set in a named list

All three packages take a list with one vector per circle. The list names become the set labels.

x <- list(
  A = c("gene1", "gene2", "gene3"),
  B = c("gene2", "gene4", "gene5"),
  C = c("gene3", "gene5", "gene6")
)

Step 2a. Venn diagram in R with ggVennDiagram (ggplot2 object)

library(ggVennDiagram)
p <- ggVennDiagram(x)
p
ggplot2::ggsave("venn.png", p)

The result is a ggplot object, so ggplot2 layers can be added, for example scale_fill_gradient(low = "grey90", high = "red"). The README lists the options label = "none", label_alpha = 0, category.names and set_color. For colour control in ggplot2 generally, see ggplot color and ggplots in R.

Step 2b. venn.diagram in R with the VennDiagram package

library(VennDiagram)
venn.plot <- venn.diagram(
  x = list(sample1 = 1:40, sample2 = 30:60),
  filename = NULL,
  disable.logging = TRUE
)
grid::grid.draw(venn.plot)

This is the pattern from the package reference manual. With filename = NULL, venn.diagram returns the grid object itself instead of writing an image file; you then draw it with grid::grid.draw(). To write a file directly, pass a filename, as in the manual’s example venn.diagram(x = list(A = 1:150, B = 121:170), filename = tempfile(pattern = "Venn_2set_simple", fileext = ".tiff")). Colours are set with the fill argument, one colour per set, and category.names defaults to names(x).

Step 2c. Venn diagram in R with ggvenn

ggvenn is the third ggplot2-based option, described on CRAN as an easy way to draw Venn diagrams with ggplot2. Load it with library(ggvenn) and use the argument names given in its CRAN manual.

Output and how to read it

Each circle is one set; the number in each region is how many items fall in exactly that combination of sets. The numbers alone do not tell you which items they are. Use base R to list the members behind a region:

Reduce(intersect, x)        # items present in every set
intersect(x$A, x$B)         # items shared by A and B
setdiff(x$A, c(x$B, x$C))   # items only in A

Save these vectors alongside the figure so the plot can be traced back to its inputs. Overlap counts are only as meaningful as the identifier matching: the same gene written as a symbol in one list and an accession in another counts as two different items.

Troubleshooting

A log file appears when I run venn.diagram

The manual describes disable.logging (default FALSE) as a Boolean to disable log file output and print to console instead. Set disable.logging = TRUE to avoid it.

ggsave does not work on my venn.diagram output

venn.diagram(filename = NULL) returns a grid object, not a ggplot object, so ggplot2::ggsave() is the wrong tool for it. Either pass a filename to venn.diagram, or use ggVennDiagram, which returns a ggplot object that ggsave accepts.

Package will not install or load

Check the Depends column above: ggVennDiagram 1.5.7 requires R 4.1.0 or later, while VennDiagram 1.8.2 requires R 3.5.0 or later.

More than seven sets

ggVennDiagram is documented for 2 to 7 sets. Its CRAN description also names an upset plot, an alternative display for larger collections of sets.

Comparing the three packages

Question VennDiagram ggVennDiagram ggvenn
Returns a ggplot object No (grid object when filename is NULL) Yes Built on ggplot2
Documented set range See manual 2 to 7 See manual
Euler plots Yes (per CRAN description) Not stated Not stated

Related plotting guide: stacked bar chart in R.

FAQ

How do I make a Venn diagram in R?

Create a named list with one vector per set, then call ggVennDiagram(x) after library(ggVennDiagram), or venn.diagram(x, filename = NULL) and grid::grid.draw() after library(VennDiagram).

What is the venn.diagram R package?

venn.diagram is the main function of the VennDiagram package on CRAN (version 1.8.2, 2026-01-11), which generates Venn and Euler plots.

Can I use ggplot2 with a Venn diagram in R?

Yes. ggVennDiagram and ggvenn are built on ggplot2, and ggVennDiagram returns a ggplot object you can extend with layers and save with ggsave.

Sources

  • CRAN, VennDiagram package page and reference manual, https://cran.r-project.org/web/packages/VennDiagram/index.html (read 2026-11-07)
  • CRAN, ggVennDiagram package page and README, https://cran.r-project.org/web/packages/ggVennDiagram/index.html (read 2026-11-07)
  • CRAN, ggvenn package page, https://cran.r-project.org/web/packages/ggvenn/index.html (read 2026-11-07)

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Venn Diagram in R: VennDiagram, ggVennDiagram and ggvenn

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →