Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 6.5 — Ordinal, Quantize, Quantile and Threshold Scales
Data Visualization · Example 2 of 2

Quantize, quantile and threshold on 365 days

Wednesday 1 January is day 0, so the first column is shifted by three days (k + 3) to line weeks up from Sunday.

Discrete scales return one of a few fixed answers, usually colours. Ordinal scales turn categories into colours. Quantize, quantile and threshold scales turn numbers into classes, and each draws the class borders in a different place, which changes what the chart says.

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.

01

Write a function classOf(rides) that returns "quiet", "normal", "busy" or "peak" for the borders 1,500, 2,500 and 3,500, using a scale. What is classOf(2500)?

02

Using the daily rides from the second example (rides), print the 75th percentile (the top border of a four-class quantile scale) and the share of days with more than 3,000 rides.

Explain it without notes

01

How do quantize and quantile cut the same data differently?

02

Why must a threshold scale's range have one more entry than its domain?

03

What happens when an ordinal scale meets a name it does not know, and how do you control it?

Quantize, quantile and threshold on 365 days

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

quantize borders: [ 1424.3, 2409.5, 3394.8 ]
quantile borders: [ 1702, 2484, 3365 ]
days per class, quantize: 34 / 142 / 100 / 89
days per class, quantile: 91 / 91 / 91 / 92
days per class, threshold: 49 / 134 / 105 / 77
1,499 -> 0  1,500 -> 1  NaN -> undefined  too few colours: b
invertExtent of the third class: [ 2409.5, 3394.8 ]
with one 90,000 day, quantize: 0:100 3:1
with one 90,000 day, quantile: 0:25 1:25 2:25 3:26