STA1000 - Data Analytics and Metrics
insta-data.csv.Today: make figures clear and honest, spot the misleading ones, then prepare the table behind them in Tableau: pivot it, add calculated fields, and merge it with a second file.

Use figures only if they are self-explanatory, help to understand your message (a figure is not a message)
Don’t duplicate the information
Tell a story! Build a narrative around your figures
Fundamentals of Data Visualization by Claus O. Wilke
Free online at clauswilke.com/dataviz
It sets out the basic principles of data visualisation. The next slides take five of them, each shown as a bad figure next to a better one.

Don’t cheat with axes: include 0 when 0 is meaningful


A bar shows its value with its length, so it has to start at zero.
A shaded area shows its value too: it also starts at 0


To zoom in on small changes, drop the shading and keep the line.
Panels you compare must share the same axis


With its own axis in each panel, a 2-point change looks as big as a 10-point one.
Make your figure easy to read and to understand


The same five numbers: sorted bars let you compare Kent and Washington at a glance.
Use extra features when they help, such as transparency and jitter


When points pile up, even transparency is not enough: count them in small hexagons instead.
Use extra features when they help, such as transparency and jitter


Transparency and a little jitter reveal the points hidden behind each other.
Use colours, but not too many


51 colours need a legend nobody can read: group them, and label the points that matter.
Keep the same colours for the same variables


And check the palette for colour-blind readers: about 1 man in 12 cannot tell red from green.
Every detail counts, and lazy work is easily spotted


Label the lines directly: a legend sends the eye back and forth, here in a different order from the lines.

Be precise, and use the title, axes and captions to do it:
For each of the next charts find what is wrong

Principle 1. The axis starts at 34%, so a rise from 35% to 39.6% is drawn as a bar more than five times taller.

Principle 1. The steps of the axis are uneven (30, 60, 90, 100, 130, 160, 190, 240, 250, 300, …): equal distances do not mean equal numbers, and the growth looks steadier than it was.

Principle 1. Each panel has its own scale, so Gutiérrez’s 19% is drawn higher than Petro’s 37%. And December, January and March are equally spaced, although February is missing.

Principles 2 and 3. A pie shows the parts of one whole, but these slices add up to 193%, and the 3D tilt distorts their sizes.

Principles 4 and 5. The rainbow colours mean nothing, and three bars are labelled 336 with three different heights: 2020 and 2021 are drawn taller than the 382 of 2016.


Principle 5. The last point, 8.6%, is drawn at the level of 9.0%. Placed correctly (right), November is the largest change of the year.

Relationship is not causation. Two series that move together need not be linked: Nicolas Cage films do not drown people. The two y-axes (Principle 1) also let you make any two lines look alike.


“Mistakes, we’ve drawn a few”: The Economist learning from its own errors in data visualisation

The original breaks Jeremy Corbyn’s bar to fit it on the axis, so 5,210 likes is drawn only a little longer than the Labour Party’s bar (Principle 1). The better version gives every bar the same scale, in thousands.


If your data is a stand-alone file, prefer transformations with Excel …
… except for pivoting your table (long versus wide) and joining two or more tables.
If your data updates itself (a cloud-hosted spreadsheet, a database, a connector), transforming in Tableau is required: the transformation runs again at every refresh.
Tableau has a dedicated tool for data transformation, Tableau Prep, but a lot can already be done in Tableau Public.
| Lecture 2 | In Tableau |
|---|---|
| 1. Extension: create a new column | a calculated field |
| 2. Reduction: keep only certain values | a filter, on the Filters shelf or the Data Source page |
| 3. Direction: arrange the row order | a sort, from the toolbar or the axis |
| 4. Aggregation: summarise a column | the aggregation of a Measure: SUM, AVG, MEDIAN, … |
| 5. Combination: join two tables | a relationship or a join (section 4) |
And long or wide? becomes a pivot, on the Data Source page.

Lecture 2: the same data can be wide, one column per quarter, or long, one row per region and quarter.

Tableau prefers long: one variable, one column, which you can put on Colour, Columns or Filters. In Excel this arrow takes a lot of copy and paste; in Tableau it takes one click: Pivot.
Wide: insta-data.csv as exported
| post_id | reach_followers | reach_non_followers |
|---|---|---|
| LR0001 | 190 | 545 |
| LR0003 | 7,737 | 2,656 |
Long: after the pivot
| post_id | audience | audience_reach |
|---|---|---|
| LR0001 | reach_followers | 190 |
| LR0001 | reach_non_followers | 545 |
| LR0003 | reach_followers | 7,737 |
| LR0003 | reach_non_followers | 2,656 |
audience and Pivot Field Values as audience_reachEach post now has two rows and every other value appears twice: count posts with CNTD (count distinct), and do not SUM the other columns.
A calculated field is Lecture 2’s Extension: a new column, computed from the others.
reach_followers appears as Reach Followers)[Likes] + [Comments] + [Saves] + [Shares]
Named Engagements, it gives every post its number of interactions, and appears in the Data pane with an = before its icon.
Row-level calculation
Evaluated once per row, before aggregation.
[Engagements] / [Reach]
computed post by post, then averaged (AVG, not the default SUM), gives you the average of the rates: 6.4%.
Aggregate calculation
Evaluated after aggregation.
SUM([Engagements]) / SUM([Reach])
gives you the rate of the totals: 5.7%, which is almost always what you meant.
In a new workbook with insta-data.csv:
reach_followers and reach_non_followers into audience and audience_reachEngagements ([Likes] + [Comments] + [Saves] + [Shares]), then the engagement rate by formatIt is possible to add more than one file but it can be done with or without joining the data.
The default method in Tableau is to use relationships: they preserve each table’s level of detail, and they are the recommended way to combine data in most cases. A join gives you more control, for instance to filter or to duplicate rows on purpose.
Relationship (the default)
Join
Employee Code in both: the line between the two boxes is the relationship


Inner: only the keys found in both tables, here 1 and 2

Left: every row of the left table; 3 has no match, so its y stays empty

Right: every row of the right table; 4 has no match, so its x stays empty

Full outer: every row of both tables, empty wherever a key has no match
insta-posts.csv has one row per post (431), meta-ads.csv one row per boosted post (127). Combined on post_id:
| Combination | Keeps | Rows |
|---|---|---|
| Inner join | the posts found in both files | 127 |
| Left join | every post, with an empty spend for the 304 organic ones | 431 |
| Right join | every boosted post | 127 |
| Full outer join | everything | 431 |
| Relationship | both tables as they are, combined view by view | 431 and 127 |
Check the number of rows after every join: it is shown above the data grid of the Data Source page. If it is not the number you expected, the join has changed your data.

Key 2 appears twice in y, so the join copies x2: 4 rows instead of 3.
Every value of x2 now counts twice, and no error message warns you.
A relationship does not copy rows: one more reason it is Tableau’s default.
In Lecture 5, a join with Loomrow’s ads by country turns €24,345.78 of spend into €106,899.36.
From Loop, download insta-posts.csv and meta-ads.csv:
insta-posts.csv, then drag meta-ads.csv next to it: a relationship on post_idformat, as a rate of the totals
Thanks for your attention and don’t hesitate to ask if you have any questions!