Learn R Programming

⚠️There's a newer version (1.12) of this package.Take me there.

Package venn

This package produces Venn diagrams for up to seven sets, using any Boolean union of set intersections.

Installation

Install the stable version from CRAN:

install.packages("venn")

Examples

A simple Venn diagram with 3 sets

venn(3)

With a vector of counts: 1 for "000", 2 for "001" etc.

venn(3, counts = 1:8)

Display the first whole set

venn("1--")

Same with

venn("A", snames = "A, B, C")

An equivalent command, from the union of all intersections

venn("100 + 110 + 101 + 111")

Same with

venn("A~B~C + AB~C + A~BC + ABC")

Adding the labels for the intersections

venn("1--", ilabels = TRUE)

Using different parameters for the borders

venn(4, lty = 5, col = "navyblue")

Using ellipses

venn(4, lty = 5, col = "navyblue", ellipse = TRUE)

A 5 sets Venn diagram

venn(5)

A 5 sets Venn diagram using ellipses

venn(5, ellipse = TRUE)

A 5 sets Venn diagram with intersection labels

venn(5, ilabels = TRUE)

And a predefined color style

venn(5, ilabels = TRUE, zcolor = "style")

A union of two sets

venn("1---- + ----1")

Same with

venn("A + E", snames = "A, B, C, D, E")

With different colors

venn("1---- , ----1", zcolor = "red, blue")

Same using SOP - sum of products notation

venn("A, E", snames = "A, B, C, D, E", zcolor = "red, blue")

Same colors for the borders

venn("1---- , ----1", zcolor = "red, blue", col = "red, blue")

A 6 sets diagram

venn(6)

Seven sets "Adelaide"

venn(7)

Artistic version

venn(c("1000000", "0100000", "0010000", "0001000",
       "0000100", "0000010", "0000001", "1111111"))

Without all borders

venn(c("1000000", "0100000", "0010000", "0001000",
       "0000100", "0000010", "0000001", "1111111"),
     borders = FALSE)

Using SOP - sum of products notation

venn("A + B~C", snames = "A, B, C, D")

The input can be a list

set.seed(12345)
x <- list(First = 1:20, Second = 10:30, Third = sample(25:50, 15))
venn(x)

Or a dataframe

set.seed(12345)
x <- as.data.frame(matrix(sample(0:1, 150, replace = TRUE), ncol = 5))
venn(x)

Using ggplot2 graphics

venn(x, ggplot = TRUE)

Increasing the border size

venn(x, ggplot = TRUE, size = 1.5)

With dashed lines

venn(x, ggplot = TRUE, linetype = "dashed")

Venn diagrams for QCA objects

library(QCA)

data(CVF)
obj <- truthTable(CVF, "PROTEST", incl.cut = 0.85)

venn(obj)

Custom labels for intersections

pCVF <- minimize(obj, include = "?")
venn(pCVF$solution[[1]], zcol = "#ffdd77, #bb2020, #1188cc")
cases <- paste(c("HungariansRom", "CatholicsNIreland", "AlbaniansFYROM",
                 "RussiansEstonia"), collapse = "\n")
coords <- unlist(getCentroid(getZones(pCVF$solution[[1]][2])))
text(coords[1], coords[2], labels = cases, cex = 0.85)

Copy Link

Version

Install

install.packages('venn')

Monthly Downloads

18,119

Version

1.11

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Adrian Dusa

Last Published

June 8th, 2022

Functions in venn (1.11)

About the venn package

Draw Venn Diagrams
venn internal functions

Internal Functions
venn

Draw and display a Venn diagram
getCentroid

Calculate the centroid of a polygon.
getZones

Calculate the union(s) of set intersections.