# How to create a beautiful Venn diagram in R?

How to create a beautiful Venn diagram in R?., Venn diagrams are diagrams that are used to visually describe sets, relationships between sets, and operations are done on them.

The Venn diagram, invented by John Venn (1834-1883), depicts the relationship between sets using circles (overlapping, intersecting, and non-intersecting).

A Venn diagram, also known as a set diagram or a logic diagram, depicts several set operations such as set intersection, set union, and set difference. It’s also used to represent a set’s subsets.

This post will show you how to make a stunning ggplot Venn diagram.

The ggvenn and ggVennDiagram packages are two extensions of the ggplot2 R package that can be used to create Venn diagrams in R.

Both package allows you to make Venn diagrams with two to four sets of dimensions.

The ggvenn package assigns a particular color to each set, which is the fundamental difference between the two packages.

The ggVennDiagram program converts the fill color of each region into a quantity, allowing us to see the variations between portions visually.

The ggvenn and ggVennDiagram functions will be used to build Venn diagrams in R.

set.seed(123) genes <- paste("gene",1:1000,sep="") x <- list( A = sample(genes,300), B = sample(genes,525), C = sample(genes,440), D = sample(genes,350) )

Using the ggVennDiagram R library, create Venn diagrams.

Install the ggVennDiagram package and run it.

Install the most recent development release.

install.packages("ggVennDiagram") library("ggVennDiagram")

**Default plot**

ggVennDiagram(x)

**Remove the background color of labels**

ggVennDiagram(x, label_alpha = 0)

**Rename the categories**

Change the color of the gradient fill

ggVennDiagram( x, label_alpha = 0, category.names = c("Stage 1","Stage 2","Stage 3", "Stage4") ) + ggplot2::scale_fill_gradient(low="red",high = "green")

**Three dimension Venn plot**

ggVennDiagram(x[1:3], label_alpha = 0)

**Two-dimension Venn plot**

How to add Circles in Plots in R with Examples ยป

ggVennDiagram(x[1:2], label_alpha = 0)

install.packages("ggvenn")

**Venn diagram with four dimensions**

It’s worth noting that the ggvenn() function gives each set its own color.

library("ggvenn")

**Default plot**

ggvenn(x)

**Change category names**

Change the fill color

names(x) <- c("S1","S2","S3", "S4") ggvenn( x, fill_color = c("#0073C2FF", "#EFC000FF", "#868686FF", "#CD534CFF"), stroke_size = 0.5, set_name_size = 4 )

**Three dimension Venn plot**

ggvenn( x, columns = c("S1", "S2", "S3"), stroke_size = 0.5 )

**Two-dimension Venn plot**

ggvenn( x, columns = c("S1", "S2"), stroke_size = 0.5 )

## Conclusion

This article explains how to make a ggplot Venn diagram with the R packages ggvern and ggVennDiagram.