Ridgeline Plot
Learn about how to build and customize ridgeline plots using ggplot2.
We'll cover the following
- What are ridgeline plots?
- Introduction to ggridges
- Creating a basic ridgeline plot
- Another approach to creating ridgeline plots
- Ridgeline plot scaling
- Modifying the ridgeline plot colors
- Grouped ridgeline plot
- Modifying colors with cyclical color scales
- Displaying quantiles
- Highlighting the tails of the distributions
What are ridgeline plots?
A ridgeline plot is a group of density plots that are overlapped to give the appearance of a mountain range. It helps us compare multiple distributions among datasets.
Introduction to ggridges
We use a package called ggridges
, created by Professor Claus O. Wilke from UT Austin, to build a ridgeline plot in R using ggplot2
. This package is a ggplot2
extension; hence, it follows the rules of grammar for ggplot2
.
The geom_ridgeline()
and geom_density_ridges()
functions are the two main geoms provided by the ggridges
package. The geom_ridgeline()
function can be used to draw lines with a filled area underneath. The geom_density_ridges()
function estimates densities from the supplied data and shows those densities using the ridgeline visualization.
It is optional to specify the height
aesthetic for these ridgeline plots. We will use the geom_density_ridges()
function in all the following examples to build our ridgeline plots.
Get hands-on with 1200+ tech skills courses.