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.
SIMILAR CHART TYPES
Stacked Bar Chart geom_bar(position = "stack")
Bars divided into segments showing total value and its composition by sub-groups.Line Chart geom_line()
Connected data points showing changes over a continuous or ordered dimension, usually time.Area Chart geom_area()
Line chart with filled area beneath, emphasizing volume and magnitude of change over time.Pie Chart geom_col() + coord_polar("y")
Circular chart divided into slices representing proportions of a whole.Treemap geom_treemap()
Nested rectangles showing hierarchical part-to-whole relationships sized by value.ALTERNATIVES FOR YOUR DATA TYPE
Bar Chart Comparison, Ranking
Compares values across discrete categories using rectangular bars proportional to values.Horizontal Bar Chart Comparison, Ranking
Horizontal bars ideal for long labels, many categories, or ranked/sorted data.Grouped Bar Chart Comparison
Clusters of bars comparing sub-groups within each category side by side.