When to use a bar chart? Sort the bars to compare
Compare La Espiga's six branches with bars, and sort them so the answer jumps out without searching for it.
Free course. Your Maestro, an AI, .
The comparing question is the most common one at work: "which branch sold the most?", "which product makes the most?", "which department spent the least?". You have several categories with no order of their own and one amount for each. The chart that answers it best is the bar chart, and on this page you'll see why, and why it almost always pays to sort the bars.
Why bars
A bar shows an amount with its length, and all the bars start from the same baseline. Comparing lengths that start in the same place is one of the things our eyes do best: we notice right away which is longer and roughly by how much. That's why a bar beats a lone number for comparing, and beats a slice of pie, where you'd have to compare angles.
That leads to a condition you'll see in depth in module 4: since a bar speaks with its length, it has to start at zero. If it starts somewhere else, the length is no longer the amount.
Each branch's 2025 total
This is the answer to the regional manager's question: "which branch sold the least in 2025?" Walk through it step by step.
Step 1 of 4
The whole chart
Six branches, one bar each. Before you look at the bars, read the bottom axis: 2025 sales, in millions of pesos, and it starts at zero. The data is synthetic, CC0.
Sorting is part of the answer
The same information in alphabetical order makes the reader do the work you didn't: jump from bar to bar, compare them two at a time and build the ranking in their head. Sorted, the ranking is already drawn. The first and last bars answer "who has the most?" and "who has the least?" without reading a single number.
There's one important exception: don't sort what already has an order. Days of the week, months, age ranges (18 to 25, 26 to 35…) or sizes have an order the reader expects. If you sort the days of the week by sales, the reader loses Monday and has to hunt for it.
Two more details you'll notice when you read other people's charts:
- Horizontal when the names are long. "Tlaquepaque" doesn't fit under a narrow bar without tilting. On their side, every name reads in full.
- One color is enough. If every bar has a different color, the reader looks for what the color means, and here it means nothing: the bars already say which branch each one is.
If you compare a lot of categories at work, say 40 products, ask your Maestro what to do with that many bars.
Your turn: fix the chart
This chart has the same data, but in the alphabetical order it came out of the spreadsheet, and with vertical bars. The question is still the manager's: which branch sold the least?
Make two changes in the JSON (the field names are in Spanish: sucursal is the branch, ventasmillones is sales in millions): 1. Sort the bars by sales: on the sucursal line, change "sort": "ascending" to "sort": "-x" (largest to smallest by the x axis). 2. Lay them down: swap "x"
Your turn
Make two changes in the JSON (the field names are in Spanish: sucursal is the branch, ventas_millones is sales in millions):
- Sort the bars by sales: on the
sucursalline, change"sort": "ascending"to"sort": "-x"(largest to smallest by the x axis). - Lay them down: swap
"x"and"y", sosucursalends up inyandventas_millonesinx.
You're done when the bars run sideways, Zapopan is on top and Tonalá at the bottom. If the preview goes blank, check that you didn't delete a comma or a brace; your Maestro can help you find it.
Edit the JSON; the preview updates when you pause.
How this maps to Altair
Altair builds this same JSON: chart.to_json() prints it. "mark": "point" is alt.Chart(df).mark_point(). Each encoding channel is an argument to .encode(), such as x=alt.X("field:Q", scale=alt.Scale(type="log")) or color="field:N". Each transform entry is a call such as .transform_filter("datum.year == 2007").
Compare your result with the walkthrough chart above: they should look the same. Notice what changed with just two moves: before, you had to look for the lowest bar; now the answer is at the edge.
When you see a bar chart in a report, ask yourself two quick questions: are the bars sorted (or do they have an order of their own that's respected)? Do they start at zero? With that, you already read better than most meetings do.
Not sure why -x sorts from largest to smallest? Ask your Maestro.