University of St.Gallen
Gilbert Fontana
October 27, 2022
Education π
Experience π οΈ
ggplot is based on the foundations in Leland Wilkinsonβs book: The Grammar of Graphics.
It is built around the following principles:
Packages π¦
Data ποΈ
country | year | centaxgdp |
---|---|---|
Denmark | 1820 | 4 |
Denmark | 1821 | 5 |
Denmark | 1822 | 5 |
Denmark | 1823 | 5 |
Denmark | 1824 | 5 |
Style π¨
Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Step 7
Step 8
df %>%
ggplot(aes(x=year,
y=centaxgdp,
group=country)) +
geom_line(aes(color=country)) +
geom_point(data = df %>% filter(year=="2020"),
aes(color=country)) +
geom_text(data = df %>% filter(year=="2020"),
aes(label=country,
color=country),
hjust = -.2,
family = font,
size = 4) +
theme(legend.position = "none")
Step 9
df %>%
ggplot(aes(x=year,
y=centaxgdp,
group=country)) +
geom_line(aes(color=country)) +
geom_point(data = df %>% filter(year=="2020"),
aes(color=country)) +
geom_text(data = df %>% filter(year=="2020"),
aes(label=country,
color=country),
hjust = -.2,
family=font,
size = 4) +
coord_cartesian(clip = "off") +
theme(legend.position = "none",
plot.margin = margin(30, 30, 30, 30))
Step 10
df %>%
ggplot(aes(x=year,
y=centaxgdp,
group=country)) +
geom_line(aes(color=country)) +
geom_point(data = df %>% filter(year=="2020"),
aes(color=country)) +
geom_text(data = df %>% filter(year=="2020"),
aes(label=country,
color=country),
hjust = -.2,
family = font,
size = 4) +
coord_cartesian(clip = "off") +
scale_color_manual(
values = met.brewer(name = "Paquin",
type = "discrete",
n = 4)) +
theme(legend.position = "none",
plot.margin = margin(30, 30, 30, 30))
Step 11
df %>%
ggplot(aes(x=year,
y=centaxgdp,
group=country)) +
geom_line(aes(color=country)) +
geom_point(data = df %>% filter(year=="2020"),
aes(color=country)) +
geom_text(data = df %>% filter(year=="2020"),
aes(label=country,
color=country),
hjust = -.2,
family = font,
size = 4) +
coord_cartesian(clip = "off") +
scale_color_manual(
values = met.brewer(name = "Paquin",
type = "discrete",
n = 4)) +
scale_y_continuous(limits = c(0,40),
expand = c(0,0)) +
theme(legend.position = "none",
plot.margin = margin(30, 30, 30, 30))
Step 12
df %>%
ggplot(aes(x=year,
y=centaxgdp,
group=country)) +
geom_line(aes(color=country)) +
geom_point(data = df %>% filter(year=="2020"),
aes(color=country)) +
geom_text(data = df %>% filter(year=="2020"),
aes(label=country,
color=country),
hjust = -.2,
family = font,
size = 4) +
coord_cartesian(clip = "off") +
scale_color_manual(
values = met.brewer(name = "Paquin",
type = "discrete",
n = 4)) +
scale_y_continuous(limits = c(0,40),
expand = c(0,0)) +
theme(
panel.grid = element_blank(),
axis.text = element_text(color = txt_col,
size = 10),
axis.title = element_text(color = txt_col,
size = 12),
legend.position = "none",
plot.margin = margin(30, 30, 30, 30),
plot.background = element_rect(fill = bg,
color = bg)
)
Step 13
df %>%
ggplot(aes(x=year,
y=centaxgdp,
group=country)) +
geom_line(aes(color=country)) +
geom_point(data = df %>% filter(year=="2020"),
aes(color=country)) +
geom_text(data = df %>% filter(year=="2020"),
aes(label=country,
color=country),
hjust = -.2,
family = font,
size = 4) +
coord_cartesian(clip = "off") +
scale_color_manual(
values = met.brewer(name = "Paquin",
type = "discrete",
n= 4 )) +
scale_y_continuous(limits = c(0,40),
expand = c(0,0)) +
labs(title = "The Rise of the\nNordic Welfare States",
caption = "Gilbert Fontana | Data: Andersson & Brambor (2019) and Eurostat",
x = "",
y = "Central government tax revenue as a share of GDP (%)") +
theme(
panel.grid = element_blank(),
axis.text = element_text(color = txt_col,
size = 10),
axis.title = element_text(color = txt_col,
size = 12),
plot.title = element_text(size = 36,
hjust =.5,
color = txt_col,
face = "bold",
margin = margin(0,0,30,0)),
plot.caption = element_text(hjust = .5,
color= txt_col),
legend.position = "none",
plot.margin = margin(30, 30, 30, 30),
plot.background = element_rect(fill = bg,
color = bg)
)