time | topic |
---|---|
1:40-1:55 | Why, philosophy and benefits |
1:55-2:15 | Organising data to map variables to plots |
2:15-2:45 | Making a variety of plots |
2:45-3:10 | Do but don’t, and cognitive principles |
3:10-3:40 | COFFEE BREAK |
time | topic |
---|---|
1:40-1:55 | Why, philosophy and benefits |
1:55-2:15 | Organising data to map variables to plots |
2:15-2:45 | Making a variety of plots |
2:45-3:10 | Do but don’t, and cognitive principles |
3:10-3:40 | COFFEE BREAK |
Is there any pattern in the residuals that indicate a problem with the model fit?
Do the teams have different shot styles?
(From the Women’s 2019 World Cup Soccer)
Is TB getting worse? (In Australia and Uruguay)
(From the World Health Organisation (WHO)]
Which is the best display to answer the previous question?
Reading data plots is subjective.
Making decisions based on data visualisations is common, where we need to be objective .
It is possible, and here is how we do that …
space
Illustrations from the Openscapes blog Tidy Data for reproducibility, efficiency, and collaboration by Julia Lowndes and Allison Horst
For each of the following data discuss whether it is in tidy form.
Data 1:
Not in tidy form
Data 2:
It’s in tidy form!
Data 3:
Not in tidy form
\[X = \left[ \begin{array}{rrrr} X_{~1} & X_{~2} & ... & X_{~p} \end{array} \right] \\ = \left[ \begin{array}{rrrr} X_{~11} & X_{~12} & ... & X_{~1p} \\ X_{~21} & X_{~22} & ... & X_{~2p} \\ \vdots & \vdots & \ddots& \vdots \\ X_{~n1} & X_{~n2} & ... & X_{~np} \end{array} \right]\]
In ggplot2
, the variables from tidy data are explicitly mapped to elements of the plot, using aesthetics
.
Basic Mappings
x
and y
to plot points in a two-dimensional spacecolor
, fill
to render as a color scalesize
maps variable to size of objectshape
maps variable to different shapesDepending on the geom
different mappings are possible, xmin
, xend
, linetype
, alpha
, stroke
, weight
…
Facets
Variables are used to subset (or condition)
Layers
Different data can be mapped onto the same plot, eg observations, and means
How are variables mapped to create this plot?
How are variables mapped to create this plot?
First get the data in tidy form
tb_ury_sa <- tb_ury %>%
filter(year > 2012) %>%
select(iso3, year,
newrel_f014:newrel_f65,
newrel_m014:newrel_m65) %>%
pivot_longer(cols=newrel_f014:newrel_m65,
names_to = "sex_age",
values_to = "count") %>%
filter(!is.na(count)) %>%
separate(sex_age, into=c("stuff",
"sex_age")) %>%
mutate(sex = str_sub(sex_age, 1, 1),
age = str_sub(sex_age, 2,
str_length(sex_age))) %>%
mutate(age = case_when(
age == "014" ~ "0-14",
age == "1524" ~ "15-24",
age == "2534" ~ "25-34",
age == "3544" ~ "35-44",
age == "4554" ~ "45-54",
age == "5564" ~ "55-64",
age == "65" ~ "65")) %>%
select(iso3, year, sex, age, count)
How many ways can we plot all three variables?
geom
: bar + position (stack, dodge, fill)
aes
:
x
count
to y
color
facet
geom
: point + smooth
aes
:
x
count
to y
color
facet
How are variables mapped to create this plot?
geom
: bar/position=“fill”
year
to x
\(~~~~\) count
to y
\(~~~~\) fill
to sex
\(~~~~\) facet
by age
Observations: More incidence among males, especially with age. No clear temporal trend.
geom
: bar
year
to x
\(~\) count
to y
\(~\) fill
and facet
to sex
\(~\) facet
by age
Incidence is higher in the middle age groups.
Where’s the temporal trend?
geom
: point, smooth
year
to x
\(~\) count
to y
\(~\) colour
and facet
to sex
\(~\) facet
by age
Temporal trend is mostly with males.
This might have slipped under the radar, but different displays had some different scaling of the data:
Slides 6, 27, 28 (Why, Example 3 4,5/5) were constructed with
Why?
The emphasis was comparing difference in trend not magnitude of values.
Use a new variable in a single data set - avoid multiple data sets (Tidy data principle)
GOOD
BAD
ggplot() +
geom_point(data = tb_ury,
aes(x=year, y=c_newinc),
colour="#F5191C") +
geom_point(data = tb_aus,
aes(x=year, y=c_newinc),
colour="#3B99B1") +
geom_smooth(data = tb_ury,
aes(x=year, y=c_newinc),
colour="#F5191C", se=F) +
geom_smooth(data = tb_aus,
aes(x=year, y=c_newinc),
colour="#3B99B1", se=F)
Cleveland and McGill (1984)
Place elements that you want to compare close to each other. If there are multiple comparisons to make, you need to decide which one is most important.
Making comparisons across plots requires the eye to jump from one focal point to another. It may result in not noticing differences.
Take the following plot, and make it more difficult to read.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.