In this article, we will be discussing the ggvenn package briefly with its working examples accordingly in the R programming language.
ggvenn Package in R
The ggvenn package provides an easy-to-use way to draw Venn diagrams using the standard ggplot2 syntax and layout. The package hence makes it possible to match the design and style of Venn diagrams to other graphics created by the ggplot2 package.
Draw Venn Diagram
In this approach to drawing the pairwise Venn diagram, the user needs to first install and import the ggvenn package to the working R console and then call the ggvenn() function from this package passed with the required parameter to get the pairwise Venn diagram accordingly in the R programming language.
Syntax to install and import the ggvenn package:
install.packages("ggvenn")
library("ggvenn")
ggvenn() function: Plot Venn diagram with supports of a data frame or list as input as an independent function.
Syntax: ggvenn( data, columns)
Parameters:
- data: A dataframe or a list as input data.
- columns: A character vector use as an index to select columns/elements.
Example 1:
In this example, we have created the list of the 2 attributes, and then with all of the ggvenn() functions from the ggvenn package passed with the list name and the name of the attribute created we are getting the Pairwise Venn Diagram in R language.
R
# Import required package
library("ggvenn")
# Create Data
venn <- list(A = sort(sample(1:500, 50)),
B = sort(sample(1:500, 50)))
# Create venn diagram Pairwise
ggvenn(venn, c("A", "B"))
Output:
Example 2:
In this example, we have created the list of the 3 attributes, and then with all of the ggvenn() functions from the ggvenn package passed with the list name and the name of the attribute created we are getting the Venn Diagram of three set in R language.
R
# Import required package
library("ggvenn")
# Create Data
venn <- list(A = sort(sample(1:100, 40)),
B = sort(sample(1:100, 40)),
C = sort(sample(1:100, 40)))
# Create venn diagram with three sets
ggvenn(venn, c("A", "B","C"))
Output:
Example 3:
In this example, we have created the list of the 4 attributes, and then with all of the ggvenn() functions from the ggvenn package passed with the list name and the name of the attribute created we are getting the Venn Diagram of four set in R language.
R
# Import required package
library("ggvenn")
# Create Data
venn <- list(A = sort(sample(1:500, 50)),
B = sort(sample(1:500, 50)),
C = sort(sample(1:500, 50)),
D = sort(sample(1:500, 50)))
# Create venn diagram with three sets
ggvenn(venn, c("A", "B","C","D"))
Output:
Similar Reads
ggpattern Package in R The ggpattern package in R is a package for creating custom and visually appealing backgrounds for ggplot2 plots. The overall article is going to cover a comprehensive introduction to the ggpattern package in R, including its features and capabilities, installation and setup, and how to use it to cr
12 min read
GGally Package in R The GGally is an extension package to ggplot2 which contains functions to reduce the complexity of combining geoms. The plots like Scatterplot Matrix, Parallel Coordinates Plot, etc, While plotting the graphs using the ggplot() function we need to combine the geom() object to specify the type of plo
4 min read
Manage packages in R In this article, we will see how to manage packages in R Programming Language using R script. What are R packages? R packages are the set of functions and datasets written in a single code and are stored in a directory called library. We will be looking at: How to Install packagesHow to Uninstall p
2 min read
pacman Package in R In this article, we will be discussing briefly the pacman package with its working examples in the R programming language. Pacman Package in R Tyler Rinker, Dason Kurkiewicz, Keith Hughitt, Albert Wang, Garrick Aden-Buie, and Lukas Burk created the Pacman R package. The package contains tools for ea
2 min read
What is the Glmnet package in R? The glmnet package in R is used to build linear regression models with special techniques called Lasso (L1) and Ridge (L2). These techniques add a small penalty to the model to avoid making it too complex which helps prevent overfitting and makes the model work better on new data.Regularized Regress
4 min read
ggsave in r The ggsave is a function in R that plays a crucial role in the process of data visualization. Specifically designed for use with ggplot2, another prominent package in the R Programming Language, ggsave allows users to save their graphs and plots with ease. This function enables users to specify vari
8 min read