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:

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,

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

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,

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

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,

Bar Plot using GGally

GGally::ggally_barDiag(iris, mapping=ggplot2::aes(x=Sepal.Length))+ labs(title="Bar Diagram using GGally")

`

**Output:

bar-plot

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,

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

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,

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

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,

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

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,

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

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,

Simple Pair Plot using GGally

GGally::ggpairs(iris, mapping=ggplot2::aes(x=Sepal.Length, y=Petal.Length)) + labs(title="Pairs plot using GGally")

`

**Output:

pairplot-r

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: