# How to create a Venn diagram in R?

R ProgrammingServer Side ProgrammingProgramming

#### Artificial Intelligence : The Future Of Programming

15 Lectures 54 mins

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### C Programming from scratch- Master C Programming

Best Seller

60 Lectures 8 hours

A Venn diagram helps to identify the common and uncommon elements between two or more than two sets of elements. This is also used in probability theory to visually represent the relationship between two or more events. To create a Venn diagram in R, we can make use of venn function of gplots package.

## Example

Consider the below vectors

x<-c(rep(c(1,2,3),times=c(4,5,8)),12,15,20)
y<-c(1:10,25)

install.packages("gplots")
library(gplots)

Creating the Venn diagram for x and y −

venn(list(x,y))

## Output If we have three variables then we will just add the third variable in venn function as shown below −

z<-c(5:15,21)
venn(list(x,y,z))

## Output 