dbfk2000
dbfk2000

Reputation: 25

How to make a venn diagram with VennDiagram () for 4 sets in R

I refer to the website (https://r-graph-gallery.com/14-venn-diagramm) to learn how to draw a venn diagram. I would like to make it with 4 sets. Where should I update/revise in the given data code on the website?

I'd like to see this kind of figure in the end.

Upvotes: 0

Views: 1695

Answers (1)

Allan Cameron
Allan Cameron

Reputation: 173743

Looking at the manual, it appears you want draw.quad.venn

library(VennDiagram)
#> Loading required package: grid
#> Loading required package: futile.logger

draw.quad.venn(72, 86, 50, 52, 44, 27, 32, 38, 32, 20, 18, 17, 11, 13, 6,
  category = c("First", "Second", "Third", "Fourth"),
  fill = c("orange", "red", "green", "blue"),
  cex = 2,
  cat.cex = 2,
  cat.col = c("orange", "red", "green", "blue")
)

Created on 2022-12-20 with reprex v2.0.2


Edit

The OP apparently prefers circles to ellipses, which neither VennDiagram nor ggVenn seem to provide. In this case, we probably just need the graphics primitives, such as

library(grid)

cg <- circleGrob(c(0.4, 0.6, 0.4, 0.6), c(0.4, 0.4, 0.6, 0.6),
                 r = 0.25, gp = gpar(fill = NA, lwd = 2))

titles <- textGrob( c("First", "Second", "Third", "Fourth"),
                   c(0.1, 0.9, 0.1, 0.9), c(0.1, 0.1, 0.9, 0.9),
                   gp = gpar(cex = 2))

values <- textGrob(c(9, 14, 1, 3, 15, 8, 2, 4, 12, 11, 5, 7, 6),
                   c(0.3, 0.7, 0.3, 0.7, 0.5, 0.7, 0.5, 0.3, 0.41, 0.59, 
                     0.41, 0.59, 0.5),
                   c(0.3, 0.3, 0.7, 0.7, 0.3, 0.5, 0.7, 0.5, 0.41, 0.41,
                     0.59, 0.59, 0.5))

grid.newpage()
grid.draw(cg)
grid.draw(titles)
grid.draw(values)

enter image description here

Upvotes: 1

Related Questions