/
hexmaps.Rmd
665 lines (602 loc) · 23.5 KB
/
hexmaps.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
---
title: "2017 New Zealand Election"
output:
flexdashboard::flex_dashboard:
theme: spacelab
self_contained: false
lib_dir: lib
mathjax: null
navbar:
- { title: "Intro", icon: "fa-home", href: "index.html", align: left }
- { title: "Dumbbells", icon: "ion-ios-settings-strong", href: "dumbbells.html", align: left }
- { title: "Hexmaps", icon: "ion-cube", href: "", align: left }
- { title: "3D Hexmaps", icon: "fa-cubes", href: "3dhex.html", align: left }
- { title: "@dakvid", icon: "fa-twitter", href: "https://twitter.com/dakvid", align: right }
social: menu
source_code: https://github.com/dakvid/election2017
---
```{r init, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(message = FALSE)
knitr::opts_chunk$set(warning = FALSE)
```
```{r setup, include=FALSE}
library(flexdashboard)
library(sf)
library(magrittr)
library(dplyr)
library(forcats)
library(purrr)
library(stringr)
library(leaflet)
library(leaflet.minicharts)
library(nzelect)
library(htmltools)
library(htmlwidgets)
begin_label_text <- "<div style='font-size:12px;float:left'>"
begin_label_text_200 <- "<div style='font-size:12px;width:200px;float:left'>"
begin_label_header <- "<span style='font-size:18px;font-weight:bold'>"
end_label_header <- "</span><br>"
end_label_text <- "</div>"
load("data_geo/nzhex.rda")
load("data_votes/GE2017.rda")
data("GE2014")
GE2014 %<>%
mutate(id = Electorate %>% str_extract("[0-9]+") %>% as.integer(),
Party = if_else(Party == "Maori Party", "Māori Party", Party))
party_voters_2017 <-
GE2017 %>%
filter(VotingType == "Party",
!str_detect(Party, "nformal")) %>%
group_by(id) %>%
summarise(Voters = sum(Votes)) %>%
ungroup()
candidate_voters_2017 <-
GE2017 %>%
filter(VotingType == "Candidate",
!str_detect(Candidate, "nformal")) %>%
group_by(id) %>%
summarise(Voters = sum(Votes)) %>%
ungroup()
party_voters_2014 <-
GE2014 %>%
filter(VotingType == "Party",
!str_detect(Party, "nformal")) %>%
group_by(id) %>%
summarise(Voters2014 = sum(Votes)) %>%
ungroup()
candidate_voters_2014 <-
GE2014 %>%
filter(VotingType == "Candidate",
!str_detect(Candidate, "nformal")) %>%
group_by(id) %>%
summarise(Voters2014 = sum(Votes)) %>%
ungroup()
getLeafletOptions <- function(minZoom, maxZoom, ...) {
leafletOptions(
crs = leafletCRS("L.CRS.Simple"),
minZoom = minZoom, maxZoom = maxZoom,
dragging = TRUE, zoomControl = FALSE,
tap = FALSE,
attributionControl = FALSE , ...)
}
getFactorPal <- function(f) {
colorFactor(colormap::colormap(
colormap = colormap::colormaps$hsv,
nshades = length(f)), f)
}
```
# {.storyboard}
### Hello HexMaps: a hexagonal cartogram of New Zealand electorates (2014-2017)
```{r hex_regions}
leaflet(options = getLeafletOptions(5.8, 5.8)) %>%
addPolygons(
data = nzhex,
label = ~nzhex %>%
transpose() %>%
map(~ paste0(begin_label_text,
begin_label_header, .x$electorate_name, end_label_header,
"In ", .x$region, ".",
end_label_text) %>% HTML()),
weight=2, color='#000000', group = 'Regions',
fillOpacity = 0.6, opacity = 1, fillColor = ~getFactorPal(region)(region),
highlightOptions = highlightOptions(weight = 4)
) %>%
addLabelOnlyMarkers(
data = nzhex %>% st_centroid(),
label = ~abbr,
labelOptions = labelOptions(
noHide = 'T', textOnly = T,
offset=c(-6,-11))
) %>%
onRender(
"function(el, t) {
var myMap = this;
// get rid of the ugly grey background
myMap._container.style['background'] = '#ffffff';
myMap.scrollWheelZoom.disable();
}"
)
```
***
This is a [cartogram](https://en.wikipedia.org/wiki/Cartogram) of the current
(2014-2017) New Zealand electorates, with one hexagon for each electorate.
Electorates have roughly equal populations, so this is a reasonable map of
population distribution. The North and South Islands should be obvious; the
Māori electorates make up a second mini NZ in the bottom right.
Why are these maps more useful than a geographic map? In short, because they don't
overrepresent rural areas and underrepresent urban areas.
[Stephen Beban (NZ)](https://thespinoff.co.nz/politics/24-09-2017/a-better-visual-breakdown-of-the-2017-election-results/) and
[Pitch Interactive (USA)](http://pitchinteractive.com/latest/tilegrams-more-human-maps/)
have more to say on the topic.
The colours here indicate the regional groupings, to help orient you to the
distorted geography. Many electorates cross regional boundaries, so these
are just a rough guide. Most notably, the Wellington region is split between
several Māori electorates. (Credit for the regional groupings to
[Chris Knox in the Herald](http://insights.nzherald.co.nz/election/)).
This hexagonal layout is due to
[Joseph Wright](http://mapdruid.blogspot.co.nz/2015/05/hexagonal-tile-map-of-new-zealand.html),
and I used his shapefiles as a base.
Chris McDowall made [a different hexagonal layout](http://web.archive.org/web/20140307180437/http://hindsight.clerestories.com/2014/01/06/chris-mcdowall-hexagonal-maps/)
for the 2011 electorates, which [I adapted](http://david.frigge.nz/nzhex2014/) in 2014.
I think I like that better in terms of the geographic layout, but it is very
skinny so it's less compact for on-screen display.
Click through the storyboard and see different data from the election
visualised in hexmaps...
### Electorate Winners: Who won the seats?
```{r hex_candidates}
electorate_winners <-
GE2017 %>%
filter(VotingType == "Candidate") %>%
group_by(id, Party) %>%
summarise(Votes = sum(Votes)) %>%
top_n(1, Votes) %>%
ungroup() %>%
inner_join(candidate_voters_2017) %>%
mutate(PerCent = round(Votes / Voters * 100, 1)) %>%
mutate(party_colour = case_when(
Party == "National Party" ~ parties_v["National"],
Party == "Labour Party" ~ parties_v["Labour"],
Party == "New Zealand First Party" ~ parties_v["NZ First"],
Party == "ACT New Zealand" ~ parties_v["ACT"],
Party == "United Future" ~ parties_v["United Future"],
Party == "Māori Party" ~ parties_v["Māori"]
)) %>%
mutate(opa = 0.1 + 0.85 * ((PerCent - min(PerCent)) / (max(PerCent) - min(PerCent))))
electorate_winners$labeltext <-
electorate_winners %>%
inner_join(nzhex) %>%
transpose() %>%
map(~ paste0(begin_label_text,
begin_label_header, .x$electorate_name, end_label_header,
.x$Party, " won with ", prettyNum(.x$Votes, big.mark=','), " votes.",
"<br>",
"<div style='width:95%'>",
"<span style='color:", .x$party_colour, ";float:left'>", .x$PerCent, "%</span>",
"<br clear='all' />",
"<span style='background:", .x$party_colour, ";width:", .x$PerCent, "%;float:left'> </span>",
"</div>",
end_label_text) %>%
HTML())
leaflet(options = getLeafletOptions(5.8, 5.8)) %>%
addPolygons(
data = inner_join(nzhex, electorate_winners),
label = ~labeltext,
weight=2, color='#000000', group = 'Electorate Seats',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addLabelOnlyMarkers(
data = nzhex %>% st_centroid(),
label = ~abbr,
labelOptions = labelOptions(
noHide = 'T', textOnly = T,
offset=c(-6,-11))
) %>%
onRender(
"function(el, t) {
var myMap = this;
// get rid of the ugly grey background
myMap._container.style['background'] = '#ffffff';
}"
)
```
***
Each hexagon is coloured for the party of the winning candidate. The strength of colour tracks
the percentage of votes the winner received --- from
`r electorate_winners %>% top_n(-1, PerCent) %$% PerCent`% for the
`r electorate_winners %>% top_n(-1, PerCent) %$% Party` in
`r electorate_winners %>% top_n(-1, PerCent) %>% inner_join(nzhex) %$% electorate_name`
to
`r electorate_winners %>% top_n(1, PerCent) %$% PerCent`% for the
`r electorate_winners %>% top_n(1, PerCent) %$% Party` in
`r electorate_winners %>% top_n(1, PerCent) %>% inner_join(nzhex) %$% electorate_name`.
### Party Votes: How are each party's voters distributed? Do they have broad or localised support?
```{r hex_parties}
party_votes <-
GE2017 %>%
filter(VotingType == "Party") %>%
group_by(id, Party) %>%
summarise(Votes = sum(Votes)) %>%
ungroup() %>%
inner_join(party_voters_2017) %>%
mutate(PerCent = round(Votes / Voters * 100, 1)) %>%
mutate(party_colour = case_when(
Party == "National Party" ~ parties_v["National"],
Party == "Labour Party" ~ parties_v["Labour"],
Party == "New Zealand First Party" ~ parties_v["NZ First"],
Party == "ACT New Zealand" ~ parties_v["ACT"],
Party == "United Future" ~ parties_v["United Future"],
Party == "Māori Party" ~ parties_v["Māori"],
Party == "Green Party" ~ parties_v["Green"],
Party == "The Opportunities Party (TOP)" ~ parties_v["TOP"],
Party == "Aotearoa Legalise Cannabis Party" ~ parties_v["Legalise Cannabis"],
Party == "Ban1080" ~ parties_v["Ban 1080"],
Party == "Conservative" ~ parties_v["Conservative"],
Party == "Internet Party" ~ parties_v["Internet"],
Party == "MANA" ~ parties_v["Mana"]
)) %>%
group_by(Party) %>%
mutate(mean_votes = mean(Votes),
opa = case_when(
Votes < 0.8 * mean_votes ~ 0.15,
Votes < 0.95 * mean_votes ~ 0.3,
Votes <= 1.05 * mean_votes ~ 0.5,
Votes <= 1.2 * mean_votes ~ 0.7,
Votes > 1.2 * mean_votes ~ 0.85
),
MaxPC = ceiling(max(PerCent))
) %>%
ungroup()
party_votes_2014 <-
GE2014 %>%
filter(VotingType == "Party") %>%
group_by(id, Party) %>%
summarise(Votes2014 = sum(Votes)) %>%
ungroup() %>%
inner_join(party_voters_2014) %>%
mutate(PerCent2014 = round(Votes2014 / Voters2014 * 100, 1)) %>%
group_by(Party) %>%
mutate(MaxPC2014 = ceiling(max(PerCent2014))) %>%
ungroup()
party_votes$labeltext <-
party_votes %>%
left_join(
party_votes_2014 %>%
filter(Party != "Internet MANA") %>%
bind_rows(
party_votes_2014 %>%
filter(Party == "Internet MANA") %>%
mutate(Party = "MANA")
) %>%
bind_rows(
party_votes_2014 %>%
filter(Party == "Internet MANA") %>%
mutate(Party = "Internet Party")
)
) %>%
group_by(Party) %>%
mutate(MaxPC = if_else(is.na(MaxPC2014), MaxPC, max(MaxPC, MaxPC2014))) %>%
ungroup() %>%
inner_join(nzhex) %>%
transpose() %>%
map(~ paste0(begin_label_text_200,
begin_label_header, .x$electorate_name, end_label_header,
prettyNum(.x$Votes, big.mark=','), " votes.",
"<br>",
"<div style='width:95%'>",
"<span style='float:left'>2017: ", .x$PerCent, "%</span>",
"<br clear='all' />",
"<span style='background:", .x$party_colour, ";width:", round(.x$PerCent / .x$MaxPC * 100), "%;float:left'> </span>",
if (is.na(.x$MaxPC2014)) {""} else {
paste0(
"<br clear='all' />",
"<span style='float:left'>2014: ", .x$PerCent2014, "%</span>",
"<br clear='all' />",
"<span style='background:", .x$party_colour, ";width:", round(.x$PerCent2014 / .x$MaxPC * 100), "%;float:left'> </span>"
)
},
"</div>",
end_label_text) %>%
HTML())
leaflet(options = getLeafletOptions(5.8, 5.8)) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "National Party")),
label = ~labeltext,
weight=2, color='#000000', group = 'National 44.4%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "Labour Party")),
label = ~labeltext,
weight=2, color='#000000', group = 'Labour 36.9%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "New Zealand First Party")),
label = ~labeltext,
weight=2, color='#000000', group = 'NZ First 7.2%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "Green Party")),
label = ~labeltext,
weight=2, color='#000000', group = 'Green 6.3%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "The Opportunities Party (TOP)")),
label = ~labeltext,
weight=2, color='#000000', group = 'TOP 2.4%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "Māori Party")),
label = ~labeltext,
weight=2, color='#000000', group = 'Māori 1.2%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "ACT New Zealand")),
label = ~labeltext,
weight=2, color='#000000', group = 'ACT 0.5%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addLabelOnlyMarkers(
data = nzhex %>% st_centroid(),
label = ~abbr,
labelOptions = labelOptions(
noHide = 'T', textOnly = T,
offset=c(-6,-11))
) %>%
addLayersControl(
baseGroups = c("National 44.4%", "Labour 36.9%", "NZ First 7.2%", "Green 6.3%",
"TOP 2.4%", "Māori 1.2%", "ACT 0.5%"),
options = layersControlOptions(collapsed = FALSE)
) %>%
onRender(
"function(el, t) {
var myMap = this;
// get rid of the ugly grey background
myMap._container.style['background'] = '#ffffff';
}"
)
```
***
Choose a party and see the tiles shaded relative to the number of voters. There are
five shades: within 5% of the average, between 5-20% over (or under) average, and more than 20% over (or under) the average.
The mouseover compares the 2017 and 2014 percentages.
Note that because it's based on absolute numbers rather than percentages, the Māori
electorates may be unexpectedly lighter because of their lower turnouts.
National and Labour have fairly complementary patterns, as do NZ First and the Greens.
### Coalition votes: Which electorates were "won" by the incumbent government?
```{r hex_coalition}
coalition_votes <-
party_votes %>%
filter(Party %in% c("National Party", "United Future", "Māori Party", "ACT New Zealand")) %>%
group_by(id) %>%
summarise(Votes = sum(Votes),
Voters = min(Voters),
party_colour = min(party_colour)) %>% # min=National
mutate(PerCent = round(Votes / Voters * 100, 1),
MaxPC = ceiling(max(PerCent))) %>%
ungroup() %>%
mutate(win = PerCent > 50)
coalition_votes_2014 <-
party_votes_2014 %>%
filter(Party %in% c("National Party", "United Future", "Māori Party", "ACT New Zealand")) %>%
group_by(id) %>%
summarise(Votes2014 = sum(Votes2014),
Voters2014 = min(Voters2014)) %>%
mutate(PerCent2014 = round(Votes2014 / Voters2014 * 100, 1),
MaxPC2014 = ceiling(max(PerCent2014))) %>%
ungroup() %>%
mutate(win2014 = PerCent2014 > 50)
coalition_votes$labeltext <-
coalition_votes %>%
left_join(coalition_votes_2014) %>%
inner_join(nzhex) %>%
transpose() %>%
map(~ paste0(begin_label_text_200,
begin_label_header, .x$electorate_name, end_label_header,
prettyNum(.x$Votes, big.mark=','), " votes.",
"<br>",
"<div style='width:95%'>",
"<span style='float:left'>2017: ", .x$PerCent, "%</span>",
"<br clear='all' />",
"<span style='background:", .x$party_colour, ";width:", round(.x$PerCent / .x$MaxPC * 100), "%;float:left'> </span>",
if (is.na(.x$MaxPC2014)) {""} else {
paste0(
"<br clear='all' />",
"<span style='float:left'>2014: ", .x$PerCent2014, "%</span>",
"<br clear='all' />",
"<span style='background:", .x$party_colour, ";width:", round(.x$PerCent2014 / .x$MaxPC * 100), "%;float:left'> </span>"
)
},
"</div>",
end_label_text) %>%
HTML())
leaflet(options = getLeafletOptions(5.8, 5.8)) %>%
addMinicharts(
lng = nzhex %>%
arrange(id) %>%
st_centroid() %>%
st_coordinates() %>%
extract(, "X"),
lat = nzhex %>%
arrange(id) %>%
st_centroid() %>%
st_coordinates() %>%
extract(, "Y"),
chartdata = coalition_votes %>%
arrange(id) %>%
transmute(Coalition = PerCent, `"Change"` = 100 - PerCent),
type = "pie",
colorPalette = c("darkblue", "orange")
) %>%
addPolygons(
data = inner_join(nzhex, coalition_votes),
label = ~labeltext,
weight=2, color='#000000', group = 'Coalition Voters',
fillColor = "black", fillOpacity = ~if_else(win, 0.2, 0),
highlightOptions = highlightOptions(weight = 4)
) %>%
addLabelOnlyMarkers(
data = nzhex %>% st_centroid(),
label = ~abbr,
labelOptions = labelOptions(
style = list("color" = "white"),
noHide = 'T', textOnly = T,
offset=c(-6,-11))
) %>%
onRender(
"function(el, t) {
var myMap = this;
// get rid of the ugly grey background
myMap._container.style['background'] = '#ffffff';
}"
)
```
***
The incumbant government is a four-party coalition between National (47.0% in 2014),
Māori (1.3%), ACT (0.7%) and United Future (0.2%). Some have argued that the election
was a referendum on the government and that the majority voted against it.
Though I'm no fan of pie charts in general, I think they're reasonable here to show the
proportion of votes for and against coalition parties, with the latter arguably in
favour of some sort of change.
The coalition received a majority in just
`r sum(coalition_votes$win)` of 71 electorates, down from
`r sum(coalition_votes_2014$win2014)` in 2014.
They increased their vote in
`r inner_join(coalition_votes, coalition_votes_2014) %>% filter(PerCent > PerCent2014) %>% nrow()`
electorates, but none by more than 4% (the 2014 national vote for the collapsed
Conservative party).
The decreases ranged up to
`r inner_join(coalition_votes, coalition_votes_2014) %>% inner_join(nzhex) %>% arrange(PerCent2014 - PerCent, PerCent) %>% tail(1) %$% {PerCent2014 - PerCent}`%
(in
`r inner_join(coalition_votes, coalition_votes_2014) %>% inner_join(nzhex) %>% arrange(PerCent2014 - PerCent, PerCent) %>% tail(1) %$% electorate_name`).
### Tiny Party Votes: Are the sub 0.5% parties evenly ignored, or do they have localised support?
```{r hex_minnows}
leaflet(options = getLeafletOptions(5.8, 5.8)) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "Aotearoa Legalise Cannabis Party")),
label = ~labeltext,
weight=2, color='#000000', group = 'Cannabis 0.3%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "Conservative")),
label = ~labeltext,
weight=2, color='#000000', group = 'Conservative 0.2%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "MANA")),
label = ~labeltext,
weight=2, color='#000000', group = 'MANA 0.1%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "Ban1080")),
label = ~labeltext,
weight=2, color='#000000', group = 'Ban1080 0.1%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "New Zealand People's Party")),
label = ~labeltext,
weight=2, color='#000000', group = "NZ People's 0.1%",
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "United Future")),
label = ~labeltext,
weight=2, color='#000000', group = 'United Future 0.1%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "NZ Outdoors Party")),
label = ~labeltext,
weight=2, color='#000000', group = 'NZ Outdoors 0.1%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "Democrats for Social Credit")),
label = ~labeltext,
weight=2, color='#000000', group = 'Social Credit 0.0%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addPolygons(
data = nzhex %>%
inner_join(party_votes %>% filter(Party == "Internet Party")),
label = ~labeltext,
weight=2, color='#000000', group = 'Internet 0.0%',
fillOpacity = ~opa, opacity = 1, fillColor = ~party_colour,
highlightOptions = highlightOptions(weight = 4)
) %>%
addLabelOnlyMarkers(
data = nzhex %>% st_centroid(),
label = ~abbr,
labelOptions = labelOptions(
noHide = 'T', textOnly = T,
offset=c(-6,-11))
) %>%
addLayersControl(
baseGroups = c("Cannabis 0.3%", "Conservative 0.2%", "MANA 0.1%", "Ban1080 0.1%", "NZ People's 0.1%",
"United Future 0.1%", "NZ Outdoors 0.1%", "Social Credit 0.0%", "Internet 0.0%"),
options = layersControlOptions(collapsed = FALSE)
) %>%
onRender(
"function(el, t) {
var myMap = this;
// get rid of the ugly grey background
myMap._container.style['background'] = '#ffffff';
}"
)
```
***
More people cast an "informal" vote than voted for any of these parties.
MANA unsurprisingly have most of their support in the Māori seats.
I'm seriously wondering if they got some votes in the Mana electorate from people assuming they
had a local focus.
The rest of the distributions are pretty much what I expected, though when a party doesn't break
100 votes in any electorate (as is the case with the bottom four) it's easy to overinterpret the noise.
The biggest surprise to me was that every party got at least 1 vote in every electorate.
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-30013353-2', 'auto');
ga('send', 'pageview');
</script>