ETF5922 Chap.5 Data Wrangling for Visualisation
Data Wrangling for Visualisation
Rows carry analytical meaning
Select changes columns, filter changes the retained population, and mutate creates variables. Grouping followed by summarise changes the unit represented by one output row.
Summaries change the grain
Pivoting changes layout between wide and long forms without changing the substantive measurements.
Joins can discard unmatched keys or multiply rows when the matching key is not unique.
Join keys before charts
A left join multiplies rows when a key on the right has more than one match.
Checking key uniqueness before plotting prevents duplicated matches from inflating totals or changing the apparent distribution.
Join keys before charts in context
Wrangling verbs alter either columns, rows or analytical grain, and those effects should be predicted before execution.
Selection retains variables, filtering retains qualifying observations, mutation derives values, arrangement changes order, grouping prepares partitions and summarising compresses them. Reshaping reorganises variable names and values, while joining introduces matches from another key space. Each operation has an expected row-count signature. Recording that signature, missing counts and important totals creates an audit trail.
When the chart later changes, the analyst can locate the responsible transformation rather than treating visual inspection as proof that the table remained valid.
What this chapter covers
- 01
Select changes columns, filter changes the retained population, and mutate creates variables.
- 02
Grouping followed by summarise changes the unit represented by one output row.
- 03
Pivoting changes layout between wide and long forms without changing the substantive measurements.
- 04
Joins can discard unmatched keys or multiply rows when the matching key is not unique.
- 05
Use select and filter to frame the reader's task
- 06
Check arrange against mutate before styling
- 07
Explain how group changes the visible comparison
- 08
Audit summarise without removing necessary context
Preserve row meaning through a summary
- 2Group by region only after confirming that one row is one order.
- 2Summarise observed sales and count non-missing rows in the same table.
- 2Carry the missing count into the annotation instead of presenting the smaller group as complete.
- 2Check that no join duplicated a region before the plot is built.
Key terms
- Observation grain
- The real-world entity represented by one row at a particular stage of a workflow.
- Grouping key
- One or more variables that partition rows before a summary calculation.
- Long format
- A structure with identifier columns plus a variable-name column and a corresponding value column.
- Join cardinality
- The one-to-one, one-to-many or many-to-many match pattern between two key sets.
Data Wrangling for Visualisation FAQ
Why can a left join increase the row count?
A left join multiplies rows when a key on the right has more than one match. Checking key uniqueness before plotting prevents duplicated matches from inflating totals or changing the apparent distribution.
What should be checked before a join?
State the key on each table, test uniqueness, predict the cardinality and record the expected row count. After joining, inspect unmatched and multiplied rows and reconcile important totals. These checks stop duplicate keys from creating a convincing but inflated visual summary.
Why preserve missing counts after summarising?
Grouping compresses many source rows into one result, so missingness can disappear precisely when the chart becomes easiest to read. Carrying observed and missing counts forward lets the viewer compare both magnitude and evidence support, especially when groups have different completeness.
How can row-count checks localise a wrangling error?
Record the expected effect after each verb: select and mutate preserve rows, filter removes declared rows, summarise reduces groups and joins follow key cardinality. The first unexpected change identifies the relevant operation. This is faster and more reliable than repairing the final plot while leaving duplicated or missing records in its data.
Exam move
Start with a table whose grain you can state in six words. Filter, mutate, group, summarise and reshape it while writing the row count after every operation. Join a second table only after testing key uniqueness. When the final plot changes, trace the difference backward to the exact transformation rather than adjusting the chart until it looks plausible.
Working through Data Wrangling for Visualisation in ETF5922? Sia is AskSia’s AI Computer Science tutor — ask any ETF5922 Data Wrangling for Visualisation question and get a clear, step-by-step explanation grounded in how ETF5922 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.