They are visual representations of the composition of legislatures.
Parliament plots often display seats color-coded by party
This is one the first attempts at creating an
R
package for parliament plots
20 June, 2018
They are visual representations of the composition of legislatures.
Parliament plots often display seats color-coded by party
This is one the first attempts at creating an R
package for parliament plots
ggparliament was first started by Thomas Leeper
Rob Hickman and I have taken over the package
The idea is that it creates ggplot2
objects of parliamentary seats that integrate seamlessly with other tidyverse
packages
ggparliament is not on CRAN
We can plot several parliament styles ranging from the horseshoe parliament (like the one we have here!) or two opposing benches (like the in UK)
Start with aggregate election results.
We include data from several countries several in the package.
For example, I will look at the Australian 2016 election.
The data frame looks like this …
library(ggparliament) australia <- election_data %>% # the data we have included is in election_data filter(year == 2016 & # filter for country, year, and legislative chamber country == "Australia" & house == "Representatives") head(australia)
We want to expand the aggregated seats per party into a long list of individual seats and plot the location of each seat on the chart
We created a function, parliament_data()
, that will do this for you!
#I am reordering the data to reflect the way the Australian parliament is structured #(gov't on right, opposition on left) but this isn't strictly neccesary australia <- australia[c(1, 5, 6, 7, 4, 3, 2), ] #run your election results through parliament_data() aus <- parliament_data(election_data = australia, # you need to specify the data frame total_seats = sum(australia$seats), # sum up the total amount of seats party_seats = australia$seats, # number of seats per party parl_rows = 4, # how many rows do we want? type = "horseshoe") # what type of parliament do we want? head(aus)
ggplot(aus, aes(x, y, colour=party_long)) + #define the data frame and how you want to colour the circles geom_parliament_seats() + # this geom plots the seats theme_void() + # we have created a theme for the package but this is optional labs(colour = "", title = "Australia House of Representatives") + scale_colour_manual(values = aus$colour, limits = aus$party_long)
## Cool. What else? - We can highlight certain seats!
This is a work in progress
We can add text to the plot as well
We’re working on ways to break up the seats by faceting.
ggplot(aus, aes(x, y, colour=party_long)) + geom_parliament_seats() + theme_void() + geom_highlight_government(government == 1) + labs(colour = "", title = "Australia House of Representatives", subtitle = "Government encircled in black.") + annotate("text", x=0, y=1, label=paste("Total: 150 MPs"), fontface="bold", size=12) + scale_colour_manual(values = aus$colour, limits = aus$party_long)