GGally Package in R (original) (raw)
Last Updated : 23 Jul, 2025
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 plot but when it comes to the GGally package it contains some built functions like:
- ggally_density() - To plot Density Plot.
- ggally_points() - To plot the ScatterPlot, etc.
which reduces the complexity of plotting graphs with the geoms like in ggplot2.
Installing and Loading the Required Packages
To be able to begin using GGally in R, you will first need to install and load the ggplot2 and the GGally packages.
R `
install.packages("ggplot2") install.packages("GGally")
library(GGally) library(ggplot2)
`
Key Plot Types in GGally
The GGally package provides several built-in functions to create a variety of visualizations. Here are some of the most commonly used plots:
1. Density Plot using ggally_density()
A density plot helps to visualize the distribution of a continuous variable.
**Syntax:
_ggally_density(data, mapping)
Where,
- **data - data set to be plotted is specified here
- **mapping - aesthetics of plot is specified here R `
Loading default dataset
data(iris)
Density Plot using GGally
GGally::ggally_density(iris,mapping=ggplot2::aes(x=Sepal.Length, y=Sepal.Width)) + labs(title="Density Plot using GGally")
`
**Output:

Density Plot using the gGally Package in R
A density plot showing the distribution of Sepal.Length and Sepal.Width from the iris dataset.
2. **Facet Density Plot using ggally_facetdensity()
The facet density plot allows you to break down a density plot by a grouping variable (e.g., species).
**Syntax:
_ggally_facetdensity(data, mapping)
Where,
- **data - data set to be plotted is specified here
- **mapping - aesthetics of plot is specified here R `
Facet Density Plot using GGally
GGally::ggally_facetdensity(iris[1:10,1:4], mapping=ggplot2::aes(x=Sepal.Length, y=Sepal.Width)) + labs(title="Facet Density Plot using GGally")
`
**Output:

Facet Density Plot using the gGally Package in R
A facet density plot that displays the distribution of Sepal.Length and Sepal.Width for different subsets of the data.
3. **Bar Diagram using ggally_barDiag()
The bar diagram can be used to visualize the frequency of a categorical variable.
**Syntax :
_ggally_barDiag(data, mapping, rescale)
**Where,
- **data - data set using
- **mapping - aesthetics being used
- **rescale - boolean to decide whether or not to rescale the count output. Only applies to numeric data R `
Bar Plot using GGally
GGally::ggally_barDiag(iris, mapping=ggplot2::aes(x=Sepal.Length))+ labs(title="Bar Diagram using GGally")
`
**Output:

Bar Plot using the gGally Package in R
A bar plot showing the distribution of Sepal.Length across the dataset.
4. Dot Plot using ggally_dot()
A dot plot is used to visualize individual data points in a continuous variable.
**Syntax:
_ggally_dot(data, mapping)
Where,
- **data - data set to be plotted is specified here
- **mapping - aesthetics of plot is specified here R `
Dot Plot using GGally
GGally::ggally_dot(iris[1:4,1:4], mapping=ggplot2::aes(x=Sepal.Length, y=Sepal.Width)) + labs(title="Dot Plot using GGally")
`
**Output:

Dot Plot using the gGally Package in R
A dot plot visualizing Sepal.Length against Sepal.Width for the first four rows of the iris dataset.
5. **Scatter Plot using ggally_points()
A scatter plot is a common method to visualize the relationship between two continuous variables.
**Syntax:
_ggally_points(data, mapping)
Where,
- **data - data set to be plotted is specified here
- **mapping - aesthetics of plot is specified here R `
Scatter Plot using GGally
GGally::ggally_points(iris, mapping=ggplot2::aes(x=Sepal.Length, y=Sepal.Width)) + labs(title="Scatter Plot using GGally")
`
**Output:

Scatter Plot using the gGally Package in R
A scatter plot showing the relationship between Sepal.Length and Sepal.Width.
6. **Network Plot using ggally_facethist()
A network plot or faceted histogram displays the distribution of data across different levels of a categorical variable.
**Syntax:
_ggally_facethist(data, mapping)
Where,
- **data - data set to be plotted is specified here
- **mapping - aesthetics of plot is specified here R `
Network Plot/Faceted Histogram using GGally
GGally::ggally_facethist(iris, mapping=ggplot2::aes(x=Sepal.Length, y=Petal.Length)) + labs(title="Network plot using GGally")
`
**Output:

Network Plot using the gGally Package in R
A faceted histogram that displays the relationship between Sepal.Length and Petal.Length.
7. Correlation Plot using ggally_cor()
**Syntax:
_ggally_cor(data, mapping, stars, method, display_grid, digits)
**Where,
- **stars - Logical value used to display stars based on significance level
- **method - correlation method need to be used (pearson)
- **display_grid - if TRUE, display aligned panel grid lines. If FALSE (default), display a thin panel border
- **digits - Number of digits need to be displayed after decimal point is specified here R `
GGally::ggally_cor(iris,mapping=ggplot2::aes(x=Sepal.Length, y=Petal.Length), stars=TRUE, digits=5, method="pearson") + labs(title="Correlation plot using GGally")
`
**Output:

Correlation Plot using the gGally Package in R
A correlation plot displaying the Pearson correlation between Sepal.Length and Petal.Length.
8. Pair Plot using ggpairs()
A pair plot is useful for visualizing relationships between multiple variables in a dataset.
**Syntax:
_ggpairs(data, mapping, columns, upper, lower, axisLables, ColumnLables)
**Where,
- **columns - columns used to make plot of a dataset is specified here
- **upper & lower - upper and lower are lists that may contain the variables 'continuous', 'combo', 'discrete', and 'na'
- **axisLabels - either "show" to display axisLabels, "internal" for labels in the diagonal plots, or "none" for no axis labels R `
Simple Pair Plot using GGally
GGally::ggpairs(iris, mapping=ggplot2::aes(x=Sepal.Length, y=Petal.Length)) + labs(title="Pairs plot using GGally")
`
**Output:

Pair Plot using the gGally Package in R
A pair plot showing the relationship between Sepal.Length and Petal.Length for multiple variables.
**Related Article: