The same flows as a matrix, with the numbers
Rows are where trips start, columns where they end. The darkest cell is Old Town to Harbour.
A flow is an amount that moves from one place to another: trips from the district where they start to the one where they end. A chord diagram draws it as ribbons round a circle and a Sankey as bands between columns. A plain matrix often reads better than both.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 4 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Sort the matrix's rows and columns by total trips, descending, and redraw it. Which district comes first and which last?
Write validFlows(matrix) that returns an error message for a matrix that is not square, or has a negative or non-numeric value, and null when it is fine.
Explain it without notes
How is a flow matrix read, and what is on its diagonal?
What does a chord's source and target hold in a chord diagram?
When is a matrix a better choice than a chord diagram?
Why must a Sankey graph have no loops, and how do you handle flows that go both ways?
Preview
Console
Nothing logged yet.Expected console output
three biggest flows: Old Town -> Harbour 713 | Harbour -> Old Town 647 | Old Town -> Old Town 554
trips that stay inside a district: 1713 of 10000 (17%)
most lopsided pair: Old Town -> Harbour has 66 more trips than the way back
cells drawn: 36 | labels: 36