This package produces Venn diagrams for up to seven sets, using any Boolean union of set intersections.
Install the stable version from CRAN:
install.packages("venn")
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, ilabels = "counts")
Or a dataframe
set.seed(12345)
x <- as.data.frame(matrix(sample(0:1, 150, replace = TRUE), ncol = 5))
venn(x, ilabels = "counts")
Using ggplot2 graphics
venn(x, ilabels = "counts", ggplot = TRUE)
Increasing the border size
venn(x, ilabels = "counts", ggplot = TRUE, size = 1.5)
With dashed lines
venn(x, ilabels = "counts", 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)