Ordinal scale: colours for districts, and its surprises
A fixed domain keeps every district on its own colour.
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.
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)?
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
How do quantize and quantile cut the same data differently?
Why must a threshold scale's range have one more entry than its domain?
What happens when an ordinal scale meets a name it does not know, and how do you control it?
Preview
Console
Nothing logged yet.Expected console output
districts: Harbour, Old Town, University, Riverside, Hillcrest, Westpark
#264653 #2a9d8f #e9c46a domain: [ 'Harbour', 'Old Town', 'University' ]
4th district: #264653 (the first colour again) a typo: #2a9d8f domain now: 5 names
known: #4e79a7 typo: #999 domain stays: 6 names
dots: 25 legend rows: 6