Streamgraph

definition - mistake - related - code

Definition


A Stream graph is a type of stacked area chart. It displays the evolution of a numeric value (Y axis) following another numeric value (X axis). This evolution is represented for several groups, all with a distinct color.

Contrary to a stacked area, there is no corner: edges are rounded what gives this nice impression of flow. Moreover, areas are usually displaced around a central axis, resulting in a flowing and organic shape.


The following example shows the evolution of baby name frequencies in the US between 1880 and 2015.

# Libraries
library(tidyverse)
library(babynames)
library(streamgraph)


# Load dataset from github
data <- babynames %>% 
  filter(name %in% c("Ashley", "Amanda", "Jessica",    "Patricia", "Linda", "Deborah",   "Dorothy", "Betty", "Helen")) %>%
  filter(sex=="F")

# Plot
data %>% 
  streamgraph(key="name", value="n", date="year") %>%
  sg_fill_brewer("BuPu")

Note: The dataset is available through the babynames R library and a .csv version is available on github.

What for


Streamchart are good to study the relative proportions of the whole. However they are bad to study the evolution of each individual group: it is very hard to substract the height of other groups at each time point. For a more accurate but less attractive figure, consider a line chart or area chart using small multiple.

Stream chart gets really useful when displayed in an interactive mode: highlighting a group gives you directly an insight of its evolution.

Variation


Even if areas are usually displaced around a central axis, it is possible to display them as for most of the chart type: over the 0 axis.

# Plot
data %>% 
  streamgraph(key="name", value="n", date="year", offset="zero") %>%
  sg_fill_brewer("BuPu")



It also possible to create a percent streamchart where the proportion of each group is displayed instead of its absolute value. Here, the total number of baby names is not available anymore. However, the most popular names at each period gets more obvious.

# Plot
data %>% 
  streamgraph(key="name", value="n", date="year", offset="expand") %>%
  sg_fill_brewer("BuPu")

Common caveats


Related


Build your own


The R and Python graph galleries are 2 websites providing hundreds of chart example, always providing the reproducible code. Click the button below to see how to build the chart you need with your favorite programing language.

R graph gallery Python gallery

Comments


Any thoughts on this? Found any mistake? Disagree? Please drop me a word on twitter or in the comment section below:

 

A work by Yan Holtz for data-to-viz.com