vignettes/e_facet-parliament_5.Rmd
e_facet-parliament_5.Rmd
To facet your parliament plot, use the split-apply-combine strategy
in a dplyr
chain.
You must:
This can be done using map from purrr
. A few examples
are as follows:
usa <- election_data %>%
filter(country == "USA" &
house == "Representatives") %>%
split(.$year) %>% # split
map(~ parliament_data(
election_data = ., # apply
party_seats = .$seats,
parl_rows = 8,
type = "semicircle"
)) %>%
bind_rows() # combine
us <- ggplot(usa, aes(x, y, colour = party_short)) +
geom_parliament_seats(size = 2.8) +
geom_highlight_government(government == 1) +
labs(
colour = NULL,
title = "American Congress",
subtitle = "The party that has control of US Congress is encircled in black."
) +
theme_ggparliament() +
scale_colour_manual(
values = usa$colour,
limits = usa$party_short
) +
theme(legend.position = "bottom") +
facet_wrap(~year, ncol = 2)
us
australia <- election_data %>%
filter(country == "Australia" &
year == "2016") %>%
split(.$house) %>% # split
map(~ parliament_data(
election_data = ., # apply
party_seats = .$seats,
parl_rows = 4,
type = "horseshoe"
)) %>%
bind_rows() # combine
au <- ggplot(australia, aes(x, y, colour = party_short)) +
geom_parliament_seats(size = 2.7) +
geom_highlight_government(government == 1) +
labs(
colour = NULL,
title = "Australian Parliament",
subtitle = "Government encircled in black."
) +
scale_colour_manual(
values = australia$colour,
limits = australia$party_short
) +
theme_ggparliament() +
theme(legend.position = "bottom") +
facet_grid(~house, scales = "free")
au
uk <- election_data %>%
filter(country == "UK") %>%
split(.$year) %>%
map(~ parliament_data(
election_data = .,
party_seats = .$seats,
group = .$government,
type = "opposing_benches"
)) %>%
bind_rows()
ggplot(
data = uk,
aes(
x = x,
y = y,
color = party_long
)
) +
geom_parliament_seats(size = 1.5) +
coord_flip() +
facet_wrap(~year, ncol = 2) +
scale_color_manual(
values = uk$colour,
limits = uk$party_long
) +
theme_ggparliament()