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 1400+ tech skills courses.