/
README.Rmd
165 lines (133 loc) · 5.05 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
---
title: "README"
author: "Zoe Meers & Robert Hickman"
date: "19/06/2018"
output: html_document
---
```{r}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE)
source("R/parliament_data.R")
source("R/helper_funcs.R")
load("data/election_data.rda")
#extra libraries for munging and plotting
library(dplyr)
library(ggplot2)
```
# Parliament plots
This package attempts to implement "parliament plots" - visual representations of the composition of legislatures that display seats color-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.
Inspiration from this package comes from: [parliamentdiagram](https://github.com/slashme/parliamentdiagram), which
is used on Wikipedia, [parliament-svg](https://github.com/juliuste/parliament-svg), which is a
javascript clone, and [a discussion on StackOverflow](http://stackoverflow.com/questions/42729174/creating-a-half-donut-or-parliamentary-seating-chart), which provided some of the code for part for the "arc" representations used in this package.
Unique parliament layouts:
==========================
Monkey Cage article :
<https://www.washingtonpost.com/news/monkey-cage/wp/2017/03/04/these-5-designs-influence-every-legislature-in-the-world-and-tell-you-how-each-governs/?utm_term=.e1e1c1c3c37b>
## Semicircle parliament
### EU, France, United States, and so on...
#### Data
```{r}
#filter the election data for the most recent US House of Representatives
us_congress <- election_data %>%
filter(country == "USA" &
year == "2016" &
house == "Representatives")
#convert this into coordinates for plotting using parliament_data()
us_congress <- parliament_data(election_data = us_congress,
type = "semicircle",
total_seats = sum(us_congress$seats),
parl_rows = 10,
party_names = us_congress$party_short,
party_seats = us_congress$seats)
#do the same for the Senate
us_senate <- election_data %>%
filter(country == "USA" &
year == "2016" &
house == "Senate")
us_senate <- parliament_data(
election_data = us_senate,
type = "semicircle",
total_seats = sum(us_senate$seats),
parl_rows = 4,
party_names = us_senate$party_short,
party_seats = us_senate$seats)
```
#### Plot
```{r}
#plot the congress data
ggplot(us_congress, aes(x, y, colour = party_short)) +
#plot the seats as dots
geom_parliament_seats() +
#highlight the government with black encircling
geom_highlight_government(government == 1) +
#other aesthetics
theme_void() +
labs(colour = "",
title = "United States Congress",
subtitle = "Government encircled in black.") +
annotate("text", x=0, y=0,
label=paste("Total:", sum(us_congress$seats[which(!duplicated(us_congress$party_long))]), "Reps"),
fontface="bold", size=8) +
scale_colour_manual(values = us_congress$colour,
limits = us_congress$party_short)
```
```{r}
#do the same for the Senate
ggplot(us_senate, aes(x, y, colour = party_long)) +
geom_parliament_seats() +
geom_highlight_government(government == 1) +
theme_void() +
labs(colour = "",
title = "United States Senate",
subtitle = "Government encircled in black.") +
annotate("text", x=0, y=0,
label=paste("Total:", sum(us_senate$seats[which(!duplicated(us_senate$party_long))]), "Reps"),
fontface="bold", size=8) +
scale_colour_manual(values = us_senate$colour,
limits = us_senate$party_long)
```
```{r}
#filter the election data for the most recent German federal election
germany <- election_data %>%
filter(year==2017 & country=="Germany") %>%
#arrange by government and seats for the plot
arrange(government, -seats)
germany <- parliament_data(election_data = germany,
total_seats = sum(germany$seats),
parl_rows = 10,
party_seats = germany$seats,
type = 'semicircle')
ggplot(germany, aes(x,y,colour=party_short))+
geom_parliament_seats()+
geom_highlight_government(government==1) +
labs(colour="Party", title="Germany 2017 Election Results") +
theme_void()+
scale_colour_manual(values = germany$colour, limits=germany$party_short)
```
## Horseshoe parliament
### Australia, New Zealand
#### Data
```{r}
australia <- election_data %>%
filter(year == 2016 &
country == "Australia" &
house == "Representatives") %>%
arrange(-government, - seats)
australia <- parliament_data(election_data = australia,
total_seats = sum(australia$seats),
party_seats = australia$seats,
parl_rows = 4,
type = "horseshoe")
```
#### Plot
```{r}
ggplot(australia, 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 = 0, label=paste("Total: 150 MPs"),
fontface="bold", size = 12) +
scale_colour_manual(values = aus$colour, limits = aus$party_long)
```