Skip to main content
v2026.11,986 entries · CC-BY 4.0

Ridgeline Plots (Joyplots): How to Read and Make Them

Ridgeline plots (joyplots) stack density curves to compare many groups. Learn to read them, with a worked bandwidth example and R and Python code.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

A ridgeline plot (also called a joyplot) stacks one smoothed density curve per group along a shared horizontal axis, with the curves overlapping slightly so the stack looks like a mountain range. Use it when you need to compare the distribution shape of many groups, such as months, sites, cohorts or conditions, in one compact figure. After reading this page you should be able to read one correctly, build one in R or Python, and describe it in a figure caption.

Ask CASRAI · free to tryQuestion about this guide? Ask CASRAI answers with linked sources. 2 free questions a day, no account.

Ask your first question freeSubscribe

What is a ridgeline plot (joyplot)?

Claus Wilke’s Fundamentals of Data Visualization (chapter 9) describes the result as a ridgeline plot “because these plots look like mountain ridgelines”. The standard version draws a kernel density estimate for each group, with the groups listed on the vertical axis and the measured variable on the horizontal axis. The same chapter notes that ridgelines scale to very large numbers of distributions and work well for showing how a distribution shifts over time. The name “joyplot” is the older label for the same chart; “ridgeline plot” is the name the ggridges documentation and Wilke’s book use.

A ridgeline plot is closely related to a violin plot. Wilke observes that it is often a more intuitive way to display the same information, because the groups read as a sequence instead of as side-by-side shapes. See the CASRAI guides on violin plots and box plots in R for the alternatives.

The estimate behind each ridge (formula)

Each ridge is a Gaussian kernel density estimate:

f̂(t) = (1 / (n·h)) · Σ φ((t − xᵢ) / h), where φ(z) = e−z²/2 / √(2π)

  • f̂(t): the estimated density at position t on the horizontal axis (the height of the ridge).
  • n: the number of observations in the group.
  • xᵢ: the i-th observed value in the group.
  • h: the bandwidth, which controls how smooth the curve is. Larger h gives a smoother, flatter ridge.
  • φ: the standard normal density, the kernel that places a small bump on every observation.

In ggridges, geom_density_ridges() computes these estimates and then plots them, so you do not supply a height aesthetic. Its stat_density_ridges() estimates the range and bandwidth from the entire data at once, which means all groups share one bandwidth.

Worked example: how bandwidth changes a ridge

Take one group with n = 5 values: 4, 5, 5, 6, 9. We compute the density at t = 7 for two bandwidths. (The values are invented for illustration only.)

Bandwidth h = 0.5

  1. Standardised distances z = (7 − xᵢ) / 0.5 are 6, 4, 4, 2 and −4.
  2. Kernel terms e−z²/2 are e−18 ≈ 0.0000000152, e−8 ≈ 0.000335 (three times: z = 4, 4 and −4) and e−2 ≈ 0.1353.
  3. Their sum is about 0.1363. Divide by n = 5: 0.02727.
  4. Divide by h·√(2π) = 0.5 × 2.5066 = 1.2533: f̂(7) ≈ 0.0218.

Bandwidth h = 2

  1. z = 1.5, 1, 1, 0.5 and −1.
  2. Kernel terms are e−1.125 ≈ 0.3247, e−0.5 ≈ 0.6065 (twice), e−0.125 ≈ 0.8825 and e−0.5 ≈ 0.6065 again. Sum ≈ 3.0267.
  3. Divide by n = 5: 0.6053. Divide by h·√(2π) = 2 × 2.5066 = 5.0133: f̂(7) ≈ 0.1207.

The same five observations give a density at t = 7 that is about 5.5 times higher with the wider bandwidth, because the wide kernels fill in the gap between the cluster near 5 and the lone value at 9. In a ridgeline plot this is why a shared bandwidth matters: if each ridge used its own bandwidth, differences in smoothness between ridges could be mistaken for differences between groups.

How to read a ridgeline plot

What you see What it means Source
Peak position Where the group’s values concentrate; compare the peaks left to right across ridges. Wilke, ch. 9
Ridge height Relative density only. There is no separate density axis, so compare shapes and relative heights, not exact density values. Wilke, ch. 9
Overlap between ridges Controlled by the scale setting: at 1 the tallest curve just touches the baseline of the next; smaller values separate the ridges and larger values overlap them. Overlap is a layout choice, not data. ggridges introduction
Long thin tails Density estimates run past the data. rel_min_height trims tails below a fraction of the highest point; 0.01 usually works. ggridges introduction
Many ridges in a row Suits large numbers of distributions and trends over time. Wilke, ch. 9

Ridgeline plot vs violin plot, box plot and histogram

  • Violin plot: same information, drawn symmetrically and side by side. Ridgelines tend to read more intuitively and scale to more groups (Wilke).
  • Box plot: summarises quartiles and hides multimodality. Choose it when you only need medians and spread; see Seaborn boxplot.
  • Histogram: Wilke advises against overlapping histograms because they often do not look good; density estimates are the usual choice in ridgelines. Use a standalone histogram for a single group.

Assumptions and common mistakes

  • Reading the height as a count or probability. The curves are scaled for display; compare shape and relative height only.
  • Letting bandwidth vary by group. Use one shared bandwidth so smoothness is comparable (ggridges does this by default).
  • Over-smoothing. A large bandwidth can hide a second mode; check suspicious unimodal ridges against the raw data. See multimodal distributions.
  • Tiny groups. A density curve from a handful of points (like the n = 5 example) is mostly a function of the bandwidth. Show points or state n per group.
  • Treating overlap as an effect. A larger scale only changes the picture.

How to report a ridgeline plot

Put the figure in the results with a numbered caption that states the variable, the grouping and the smoothing. Suggested wording (adapt it to your data):

Figure 2. Ridgeline plot of [variable] by [group]. Each curve is a Gaussian kernel density estimate with a bandwidth shared across groups; heights are relative within the figure. n per group: A = 5, B = 5, C = 5.

State the bandwidth rule or value and any tail trimming in the caption or methods, and report the group summaries you rely on (medians, SDs) in text or a table. For further figure advice see data visualization examples for research figures.

How to make a ridgeline plot in R, Python or Excel

R (ggridges)

library(ggplot2)
library(ggridges)
ggplot(iris, aes(x = Sepal.Length, y = Species)) +
  geom_density_ridges(scale = 1, rel_min_height = 0.01)

The base call ggplot(iris, aes(x = Sepal.Length, y = Species)) + geom_density_ridges() is the ggridges introduction’s own example; scale and rel_min_height are the settings described above.

Python (matplotlib and SciPy)

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde

groups = {"A": [4, 5, 5, 6, 9], "B": [6, 7, 8, 8, 10], "C": [9, 10, 11, 12, 12]}
grid = np.linspace(0, 16, 400)
fig, ax = plt.subplots()
for i, (name, values) in enumerate(groups.items()):
    dens = gaussian_kde(values, bw_method=0.5)(grid)  # factor applied to the data SD
    dens = dens / dens.max()                          # same peak height per ridge
    ax.fill_between(grid, i, i + 1.2 * dens, alpha=0.7, zorder=len(groups) - i)
    ax.plot(grid, i + 1.2 * dens, color="black", lw=0.8, zorder=len(groups) - i)
ax.set_yticks(range(len(groups)))
ax.set_yticklabels(groups.keys())
ax.set_xlabel("Value")
plt.show()

This draws each ridge from its own baseline with later groups drawn behind earlier ones. In SciPy, a scalar bw_method is a factor multiplied by the data’s standard deviation, so unlike ggridges each group here gets its own absolute bandwidth; for strict comparability, compute one bandwidth from the pooled data and convert it to a factor per group. Normalising every peak to the same height also hides differences in density between groups.

Excel

This page does not cover Excel: build the density estimates in R or Python and export the figure.

FAQ

What is a ridgeline plot used for?

Comparing the shape of a distribution across many groups or time points in one figure, especially when side-by-side density plots would not fit.

Is a ridgeline plot the same as a joyplot?

Yes. Joyplot is the earlier name; ridgeline plot is the name used in current documentation such as ggridges.

Can I read exact density values from a ridgeline plot?

No. There is no separate density axis, so only shapes and relative heights are comparable.

Should I use a histogram in a ridgeline plot?

Wilke advises against overlapping histograms because they often do not look good; density estimates are the usual choice.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Ridgeline Plots (Joyplots): How to Read and Make Them

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →