Memra

The time axis is categorical; stacked hides everything but the bottom

◈ 6 cards

A line chart spaces its categories equally, so 2019, 2020, 2024 lie about a four-year gap — use scatter with straight lines for a numeric x. Clustered compares within groups, stacked shows totals, 100 % stacked shows mix; beside = TRUE is clustered.

A line chart does not know what a year is

Maple & Birch's annual sales were 1.8 M in 2019, 2.1 M in 2020 and 3.0 M in 2024 — nothing was recorded for the three years between. Put the three rows on a line chart and the horizontal axis reads 2019 · 2020 · 2024 at equal spacing. In Sheets and Excel the line chart's horizontal axis is a category axis: it places one label per row, evenly, whatever the labels say. The line therefore climbs from 2020 to 2024 at the same visual slope as from 2019 to 2020, and the reader sees a steady rise when the record shows one step and then a four-year silence.

When the x variable is a number — a year, a month count, an ad-spend figure — the honest chart is a scatter plot with straight lines (Excel: Scatter with Straight Lines; Sheets: a scatter with a trendline or a line chart with the x column set as a numeric axis). Its horizontal axis is a value axis: 2024 sits four units right of 2020, and the gap is visible. Base R draws it with plot(year, sales, type = "b")"b" for both points and lines — and numeric x is placed at its value by default.

Use the line chart when the periods are complete and equally spaced — Jan, Feb, Mar — which is exactly when equal spacing tells the truth.

Worked example — one pivot, three column charts

The Module 7 pivot of Sum of amount with channel in Rows and prov in Columns, in R:

> xtabs(amount ~ channel + prov, data = orders)
        prov
channel    AB   BC   ON   QC
  Online 1320  720  930   90
  Store   980  640 1065  395

Eight numbers, and three different column charts, each answering a different question.

Clustered (side by side). Within each province, an Online column next to a Store column. The question it answers: within a province, which channel is bigger? ON: Store edges Online (1065 vs 930); QC: Store is four times Online. It cannot show the province total without the reader adding two columns by eye.

Stacked. One column per province, Online on the bottom and Store on top. The column height is the province total — AB 2300, ON 1995, BC 1360, QC 485 — so the question answered is which province sells most, and roughly how is it split? The cost: only the bottom series has a readable height. Store's ON segment runs from 930 to 1995; the reader must subtract to get 1065, and comparing Store across provinces means comparing segments that start at different heights.

100 % stacked. Every column stretched to the same height, segments as shares. The question: what is the channel mix in each province, regardless of size? ON is 46.6 % Online; QC is 18.6 % Online. What it hides is the totals entirely — QC's column is as tall as AB's.

So: comparison within groups → clustered; composition with totals → stacked; composition as mix → 100 % stacked.

In base R the switch is one argument: barplot(xtabs(amount ~ channel + prov, data = orders), beside = TRUE, legend = TRUE) draws the clustered chart; beside = FALSE (the default) stacks. The table's rows become the series — channel — and its columns become the groups along the axis — province; swap the formula to prov + channel to group by channel instead. The 100 % version is prop.table(…, 2) from Lesson 7.4 handed to barplot().

Type the clustered call, then choose the variant

Type the barplot line. The questions give a business question and ask for clustered, stacked, 100 % stacked, or a different chart altogether.

CRISP-DM: still data understanding → explore data — three charts of one pivot are three explorations of the same summary.

NORMAL ~/memra/learn/afm-112/line-scatter-and-composition-charts utf-8 LF