This package attempts to implement “parliament plots” - visual representations of the composition of legislatures that display seats colour-coded by party. The input is a data frame containing one row per party, with columns representing party name/label and number of seats, respectively.
This R
package is a ggplot2
extension.
To install the package:
::install_github("robwhickman/ggparliament") devtools
Inspiration from this package comes from: parliamentdiagram, which is used on Wikipedia, parliament-svg, which is a javascript clone, and a discussion on StackOverflow, which provided some of the code for part for the “arc” representations used in this package.
If you have any issues, please note the problem and inform us!
#filter the election data for the most recent US House of Representatives
<- election_data %>%
us_house filter(country == "USA" &
== 2016 &
year == "Representatives")
house
<- parliament_data(election_data = us_house,
us_house type = "semicircle",
parl_rows = 10,
party_seats = us_house$seats)
<- election_data %>%
us_senate filter(country == "USA" &
== 2016 &
year == "Senate")
house
<- parliament_data(
us_senate election_data = us_senate,
type = "semicircle",
parl_rows = 4,
party_seats = us_senate$seats)
<- ggplot(us_house, aes(x, y, colour = party_short)) +
representatives geom_parliament_seats() +
#highlight the party in control of the House with a black line
geom_highlight_government(government == 1) +
#draw majority threshold
draw_majoritythreshold(n = 218, label = TRUE, type = 'semicircle')+
#set theme_ggparliament
theme_ggparliament() +
#other aesthetics
labs(colour = NULL,
title = "United States House of Representatives",
subtitle = "Party that controls the House highlighted.") +
scale_colour_manual(values = us_house$colour,
limits = us_house$party_short)
representatives
<- ggplot(us_senate, aes(x, y, colour = party_long)) +
senate geom_parliament_seats() +
geom_highlight_government(government == 1) +
# add bar showing proportion of seats by party in legislature
geom_parliament_bar(colour = colour, party = party_long) +
theme_ggparliament(legend = FALSE) +
labs(colour = NULL,
title = "United States Senate",
subtitle = "The party that has control of the Senate is encircled in black.") +
scale_colour_manual(values = us_senate$colour,
limits = us_senate$party_long)
senate
<- election_data %>%
germany filter(year == 2017 &
== "Germany")
country
<- parliament_data(election_data = germany,
germany parl_rows = 10,
type = 'semicircle',
party_seats = germany$seats)
<- ggplot(germany, aes(x, y, colour = party_short)) +
bundestag geom_parliament_seats(size = 3) +
geom_highlight_government(government == 1) +
labs(colour="Party",
subtitle = "Government circled in black.") +
theme_ggparliament(legend = TRUE) +
scale_colour_manual(values = germany$colour,
limits = germany$party_short)
bundestag
#data preparation
<- election_data %>%
uk_17 filter(country == "UK" &
== "2017") %>%
year parliament_data(election_data = .,
party_seats = .$seats,
parl_rows = 12,
type = "opposing_benches",
group = .$government)
<- ggplot(uk_17, aes(x, y, colour = party_short)) +
commons geom_parliament_seats(size = 3) +
theme_ggparliament() +
coord_flip() +
labs(colour = NULL,
title = "UK parliament in 2017") +
scale_colour_manual(values = uk_17$colour,
limits = uk_17$party_short)
commons
<- election_data %>%
australia filter(country == "Australia" &
== "Representatives" &
house == 2016) %>%
year parliament_data(election_data = .,
party_seats = .$seats,
parl_rows = 4,
type = "horseshoe")
<-ggplot(australia, aes(x, y, colour = party_short)) +
au_rep geom_parliament_seats(size = 3.5) +
geom_highlight_government(government == 1, colour = "pink", size = 4) +
draw_majoritythreshold(n = 76,
label = TRUE,
linesize = 0.5,
type = 'horseshoe') +
theme_ggparliament() +
theme(legend.position = 'bottom') +
labs(colour = NULL,
title = "Australian Parliament",
subtitle = "Government circled in pink.") +
scale_colour_manual(values = australia$colour,
limits = australia$party_short)
au_rep