Intro Ggplot2 3
Intro Ggplot2 3
scratch
I N T R O D U C T I O N T O D ATA V I S U A L I Z AT I O N W I T H G G P L O T 2
Rick Scave a
Founder, Scave a Academy
The themes layer
All non-data ink
Three types
type
text
line
rectangle
Three types
text line
axis.title axis.ticks
axis.title.x axis.ticks.x
axis.title.x.top axis.ticks.x.top
axis.title.x.bottom axis.ticks.x.bottom
axis.title.y axis.ticks.y
axis.title.y.left axis.ticks.y.left,
axis.title.y.right axis.ticks.y.right
axis.line
axis.line.x
axis.line.x.top
axis.line.x.bottom
axis.line.y
axis.line.y.left
axis.line.y.right
Rick Scave a
Founder, Scave a Academy
Ways to use themes
1. From scratch (last video)
3. Built-in themes
ggplot2 or ggthemes packages
3. Built-in themes
ggplot2 or ggthemes packages
z +
theme_classic()
z +
theme_classic() +
theme(text = element_text(family = "serif"))
3. Built-in themes
ggplot2 or ggthemes packages
library(ggthemes)
z +
theme_tufte()
3. Built-in themes
ggplot2 or ggthemes packages
# Alternatively
# theme_set(theme_grey())
Rick Scave a
Founder, Scave a Academy
Our goal, an effective explanatory plot
Observations: 142
Variables: 3
$ country <fct> "Afghanistan", "Albania", "Algeria", "Angola", "Argentina", "Au...
$ lifeExp <dbl> 43.828, 76.423, 72.301, 42.731, 75.320, 81.235, 79.829, 75.635,...
$ continent <fct> Asia, Europe, Africa, Africa, Americas, Oceania, Europe, Asia, ...
1 We would begin with our complete data set, which contains three variables for 142 countries.
Observations: 20
Variables: 3
$ country <fct> "Swaziland", "Mozambique", "Zambia", "Sierra Leone", "Lesotho...
$ lifeExp <dbl> 39.613, 42.082, 42.384, 42.568, 42.592, 42.731, 43.487, 43.82...
$ continent <fct> Africa, Africa, Africa, Africa, Africa, Africa, Africa, Asia,...
>