VOOZH about

URL: https://www.geeksforgeeks.org/r-language/ggally-package-in-r/

⇱ GGally Package in R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

GGally Package in R

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.

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

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,

  • data - data set to be plotted is specified here
  • mapping - aesthetics of plot is specified here

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,

  • 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

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,

  • data - data set to be plotted is specified here
  • mapping - aesthetics of plot is specified here

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,

  • data - data set to be plotted is specified here
  • mapping - aesthetics of plot is specified here

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,

  • data - data set to be plotted is specified here
  • mapping - aesthetics of plot is specified here

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,

  • 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

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,

  • 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

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:

Comment

Explore