liveBook · Manning

Sankey diagram

As explained in Statistics Slam Dunk

A Sankey diagram is a flow visualization whose link widths represent quantities moving between nodes.

A Sankey diagram visualizes quantities flowing between adjacent sets of nodes. Each connector, or link, becomes wider as the quantity it represents increases, allowing several categorical transitions to be read in one graphic. section 3.7

Build a Sankey diagram by turning sequential categorical relationships into node and link data:

  • Prepare categorical variables, using transformations such as truncation and case_when() to create usable groups like <20, 20-39, and 40-59. section 3.7
  • Count each adjacent pair of categories with count(), such as country and college attendance, age and position, or draft segment and win-share group. section 3.7
  • Create a nodes data frame containing category names and a links data frame containing source, target, and value columns. section 3.7
  • Render the result with sankeyNetwork(), specifying Links, Nodes, Value, NodeID, fontSize, and nodeWidth. section 3.7

NBA draft-flow analysis

A first-round NBA draft analysis can connect birthplace, college attendance, draft-entry age, position, pick segment, and win-share group. The resulting flow shows that most players were born in the United States, attended college, entered between ages 19 and 22, and played forward or guard. Only a fraction accumulated many win shares, with most of those players selected in the 1-5 pick segment. section 3.7

Figure 3.5 A sample Sankey diagram created for illustrative purposes only. The vertical rectangles are nodes, and the bands connecting a pair of nodes are links. The width of the links is a representation of quantity. In this example, more text messages are sent than emails, more men receive some type of digital communication than do women, and most men then respond affirmatively, whereas most women do not.
CH03_F05_Sutton

Use the diagram to compare link widths across stages: the illustrative campaign example contrasts communication channels, gender groups, and affirmative responses. section 3.7

How Statistics Slam Dunk covers it

How deep it goes
Explains link widths, data preparation, node-link structures, R rendering, and interpretation without developing the visualization internals.
Examples
Uses employment applications, nonprofit finances, marketing responses, and NBA draft players as flow examples.
What it assumes
Assumes segmented data and basic categorical counting, while demonstrating preparation from raw variables through grouped flows.
What you can do after
Builds and interprets Sankey diagrams from grouped categorical flows using R data frames and sankeyNetwork().
How it connects
Connects segmentation analysis with data visualization and target variables in machine learning.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.