forked from zmeers/ggparliament
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
249 lines (184 loc) · 6.88 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
---
title: "README"
output: github_document
pagetitle: README
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE)
#library(ggparliament)
library(dplyr)
library(tidyr)
library(ggplot2)
source("R/parliament_data.R")
source("R/geom_parliament_seats.R")
source("R/geom_highlight_government.R")
source("R/geom_emphasize_parliamentarians.R")
source("R/helper_funcs.R")
source("R/draw_majoritythreshold.R")
source("R/draw_partylabels.R")
source("R/draw_majoritythreshold.R")
source("R/draw_totalseats.R")
source("R/theme_ggparliament.R")
source("R/geom_parliament_bar.R")
load("data/election_data.rda")
```
# Status
[![Build Status](https://travis-ci.org/RobWHickman/ggparliament.png)](https://travis-ci.org/RobWHickman/ggparliament)
![CRAN Status](https://www.r-pkg.org/badges/version/ggparliament)
![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/ggparliament)
<img src = "man/figures/HexSticker.png" align = "right" width = "200"/>
# `ggparliament`: Parliament plots
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 and is now on CRAN. Please install the stable version in `R` by running:
```{r, eval=FALSE}
install.packages("ggparliament")
```
To install the package from source:
```{r, eval=FALSE}
devtools::install_github("robwhickman/ggparliament")
```
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.
If you have any issues, please note the problem and inform us!
## Election data
`ggparliament` provides election data from the following countries.
```{r}
election_data %>%
distinct(year, country, house) %>%
arrange(country, year)
```
We also provide the following vignettes for further explanation:
1. Basic parliament plots
2. Labelling parties
3. Drawing the majority threshold line
4. Highlighting parties in power
5. Faceting legislatures
6. Emphasizing certain seats
7. Visualizaing overhang seats in MMP electoral systems
8. Arranging seat order in ggparliament plots.
Quick `ggparliament` examples can be viewed below.
## Semicircle parliament
### EU, France, United States, and so on...
### Plot of US House of Representatives
```{r}
#filter the election data for the most recent US House of Representatives
us_house <- election_data %>%
filter(country == "USA" &
year == 2016 &
house == "Representatives")
us_house <- parliament_data(election_data = us_house,
type = "semicircle",
parl_rows = 10,
party_seats = us_house$seats)
us_senate <- election_data %>%
filter(country == "USA" &
year == 2016 &
house == "Senate")
us_senate <- parliament_data(
election_data = us_senate,
type = "semicircle",
parl_rows = 4,
party_seats = us_senate$seats)
```
```{r, fig.width=8, fig.height=4}
representatives <- ggplot(us_house, aes(x, y, colour = party_short)) +
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
```
### Plot of US Senate
```{r, fig.width=6, fig.height=4}
senate <- ggplot(us_senate, aes(x, y, colour = party_long)) +
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
```
### Plot of German Bundestag
```{r, fig.height=4, fig.width=8}
germany <- election_data %>%
filter(year == 2017 &
country == "Germany")
germany <- parliament_data(election_data = germany,
parl_rows = 10,
type = 'semicircle',
party_seats = germany$seats)
bundestag <- ggplot(germany, aes(x, y, colour = party_short)) +
geom_parliament_seats(size = 3) +
labs(colour="Party") +
theme_ggparliament(legend = TRUE) +
scale_colour_manual(values = germany$colour,
limits = germany$party_short)
bundestag
```
## Opposing Benches Parliament
### United Kingdom
```{r, fig.height = 4}
#data preparation
uk_17 <- election_data %>%
filter(country == "UK" &
year == "2017") %>%
parliament_data(election_data = .,
party_seats = .$seats,
parl_rows = 12,
type = "opposing_benches",
group = .$government)
commons <- ggplot(uk_17, aes(x, y, colour = party_short)) +
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
```
## Horseshoe parliament
### Australia, New Zealand
```{r}
australia <- election_data %>%
filter(country == "Australia" &
house == "Representatives" &
year == 2016) %>%
parliament_data(election_data = .,
party_seats = .$seats,
parl_rows = 4,
type = "horseshoe")
```
### Plot of Australian parliament
```{r}
au_rep <-ggplot(australia, aes(x, y, colour = party_short)) +
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
```