Get Started →
TrendComposition Time SeriesCategoricalNumerical

Stacked Area Chart

ggplot2: geom_area(position = "stack") · Package: ggplot2 · Variables: 1 temporal + 1 numerical + 1 categorical

WHAT IS A STACKED AREA CHART?

A stacked area chart layers multiple area series on top of each other to show both the total and the composition of that total over time. It answers "how has the mix of components changed over time, and what is the overall trend?" For example, revenue by product line over quarters, or website traffic by source over months. The topmost line shows the total; the colored bands show each component contribution. Best with 2-6 series. In ggplot2, use geom_area() with position = "stack" and a fill aesthetic for the grouping variable.

BEST FOR

  • · Composition changes over time
  • · Component contributions to total
  • · 2-6 category series

AVOID WHEN

  • · Reading individual series values precisely
  • · More than 7 categories
  • · Vastly different scales

R + GGPLOT2 CODE EXAMPLE

ggplot2
library(tidyr)
df <- economics[, c("date", "pce", "psavert")]
df_long <- pivot_longer(df, -date, names_to = "metric", values_to = "value")
ggplot(df_long, aes(x = date, y = value, fill = metric)) +
  geom_area(alpha = 0.7) +
  labs(title = "Stacked Area: PCE vs Savings", x = "Date", y = "Value")

Run this code now

Paste the code above into RChat and see the stacked area chart rendered instantly in your browser.

Try RChat Free →

SIMILAR CHART TYPES

ALTERNATIVES FOR YOUR DATA TYPE