-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLocal Election.Rmd
More file actions
730 lines (645 loc) · 42.5 KB
/
Local Election.Rmd
File metadata and controls
730 lines (645 loc) · 42.5 KB
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
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
---
title: "Local Election"
author: "Po-Sheng Lee"
date: "2018/12/20"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(tidyverse)
library(readxl)
library(magrittr)
```
```{r tidy2018 data}
#台北
taipei_2018 <- read_excel("data/縣表3-1-100(臺北市).xls")
taipei_2018 %<>%
rename("行政區別" = `107年臺北市市長選舉候選人在各投開票所得票數一覽表`, "里別" = X__1,
"民進黨候選人得票數" = X__5, "國民黨候選人得票數" = X__4, "無黨籍候選人得票數" = X__6,
"投票數" = X__10,"選舉人數"= X__14) %>%
map(~gsub('\\s+', '',x = .)) %>%
as_data_frame() %>%
mutate(選舉年份 = 2018, 縣市別 = "台北市",
國民黨候選人 = "丁守中", 民進黨候選人 = "姚文智", 無黨籍候選人 = "柯文哲",
民進黨候選人得票數 = as.numeric(民進黨候選人得票數),
國民黨候選人得票數 = as.numeric(國民黨候選人得票數),
無黨籍候選人得票數 = as.numeric(無黨籍候選人得票數),
選舉人數 = as.numeric(選舉人數),
投票數 = as.numeric(投票數)) %>%
select(選舉年份, 縣市別, 行政區別, 里別, 國民黨候選人, 民進黨候選人, 無黨籍候選人,
國民黨候選人得票數, 民進黨候選人得票數, 無黨籍候選人得票數, 投票數, 選舉人數) %>%
drop_na() %>%
group_by(行政區別, 里別) %>%
mutate(國民黨候選人得票數 = sum(國民黨候選人得票數), 民進黨候選人得票數 = sum(民進黨候選人得票數),
無黨籍候選人得票數 = sum(無黨籍候選人得票數),
選舉人數 = sum(選舉人數), 投票數 = sum(投票數)) %>%
distinct(行政區別, 里別, .keep_all = T) %>%
ungroup()
taipei_2018 %<>%
mutate(國民黨候選人得票率 = 國民黨候選人得票數/投票數, 民進黨候選人得票率 = 民進黨候選人得票數/投票數,
無黨籍候選人得票率 = 無黨籍候選人得票數/投票數, 投票率 = 投票數/選舉人數,
政黨色 = case_when(
國民黨候選人得票數 > 無黨籍候選人得票數 & 國民黨候選人得票數 > 民進黨候選人得票數 ~ "Blue",
無黨籍候選人得票數 > 國民黨候選人得票數 & 無黨籍候選人得票數 > 民進黨候選人得票數 ~ "Grey",
民進黨候選人得票數 > 無黨籍候選人得票數 & 民進黨候選人得票數 > 國民黨候選人得票數 ~ "Green"))
write_excel_csv(taipei_2018, "data/2018台北市候選人得票概況(村里別)")
#新北
newtaipei_2018 <- read_excel("data/縣表3-1-200(新北市).xls")
newtaipei_2018 %<>%
rename("行政區別" = `107年新北市市長選舉候選人在各投開票所得票數一覽表`, "里別" = X__1,
"民進黨候選人得票數" = X__3, "國民黨候選人得票數" = X__4,
"投票數" = X__7, "選舉人數" = X__11) %>%
map(~gsub('\\s+', '',x = .)) %>%
as_data_frame() %>%
mutate(選舉年份 = 2018, 縣市別 = "新北市", 國民黨候選人 = "侯友宜", 民進黨候選人 = "蘇貞昌",
民進黨候選人得票數 = as.numeric(民進黨候選人得票數),
國民黨候選人得票數 = as.numeric(國民黨候選人得票數),
投票數 = as.numeric(投票數),
選舉人數 = as.numeric(選舉人數)) %>%
select(選舉年份, 縣市別, 行政區別, 里別, 國民黨候選人, 民進黨候選人,
國民黨候選人得票數, 民進黨候選人得票數, 投票數, 選舉人數) %>%
drop_na() %>%
group_by(行政區別, 里別) %>%
mutate(國民黨候選人得票數 = sum(國民黨候選人得票數), 民進黨候選人得票數 = sum(民進黨候選人得票數),
投票數 = sum(投票數), 選舉人數 = sum(選舉人數)) %>%
distinct(行政區別, 里別, .keep_all = T) %>%
ungroup()
newtaipei_2018 %<>%
mutate(國民黨候選人得票率 = 國民黨候選人得票數/投票數, 民進黨候選人得票率 = 民進黨候選人得票數/投票數,
`得票率差(百分點)` = (國民黨候選人得票率 - 民進黨候選人得票率)*100,
得票數差 = 國民黨候選人得票數 - 民進黨候選人得票數, 投票率 = 投票數/選舉人數,
政黨色 = if_else(得票數差 > 0, "Blue", "Green"))
write_excel_csv(newtaipei_2018, "data/2018新北市候選人得票概況(村里別)")
#桃園
taoyuan_2018 <- read_excel("data/縣表3-1-300(桃園市).xls")
taoyuan_2018 %<>%
rename("行政區別" = `107年桃園市市長選舉候選人在各投開票所得票數一覽表`, "里別" = X__1,
"民進黨候選人得票數" = X__7, "國民黨候選人得票數" = X__4, "投票數" = X__10, "選舉人數" = X__14) %>%
map(~gsub('\\s+', '',x = .)) %>%
as_data_frame() %>%
mutate(選舉年份 = 2018, 縣市別 = "桃園市", 國民黨候選人 = "陳學聖", 民進黨候選人 = "鄭文燦",
民進黨候選人得票數 = as.numeric(民進黨候選人得票數),
國民黨候選人得票數 = as.numeric(國民黨候選人得票數),
投票數 = as.numeric(投票數),
選舉人數 = as.numeric(選舉人數)) %>%
select(選舉年份, 縣市別, 行政區別, 里別, 國民黨候選人, 民進黨候選人,
國民黨候選人得票數, 民進黨候選人得票數, 投票數, 選舉人數) %>%
drop_na() %>%
group_by(行政區別, 里別) %>%
mutate(國民黨候選人得票數 = sum(國民黨候選人得票數), 民進黨候選人得票數 = sum(民進黨候選人得票數),
投票數 = sum(投票數), 選舉人數 = sum(選舉人數)) %>%
distinct(行政區別, 里別, .keep_all = T) %>%
ungroup() %>%
mutate(國民黨候選人得票率 = 國民黨候選人得票數/投票數, 民進黨候選人得票率 = 民進黨候選人得票數/投票數,
`得票率差(百分點)` = (國民黨候選人得票率 - 民進黨候選人得票率)*100,
得票數差 = 國民黨候選人得票數 - 民進黨候選人得票數, 投票率 = 投票數/選舉人數,
政黨色 = if_else(得票數差 > 0, "Blue", "Green"))
write_excel_csv(taoyuan_2018, "data/2018桃園市候選人得票概況(村里別)")
#台中
taichung_2018 <- read_excel("data/縣表3-1-400(臺中市).xls")
taichung_2018 %<>%
rename("行政區別" = `107年臺中市市長選舉候選人在各投開票所得票數一覽表`, "里別" = X__1,
"民進黨候選人得票數" = X__4, "國民黨候選人得票數" = X__5, "投票數" = X__8, "選舉人數" = X__12) %>%
map(~gsub('\\s+', '',x = .)) %>%
as_data_frame() %>%
mutate(選舉年份 = 2018, 縣市別 = "台中市", 國民黨候選人 = "盧秀燕", 民進黨候選人 = "林佳龍",
民進黨候選人得票數 = as.numeric(民進黨候選人得票數),
國民黨候選人得票數 = as.numeric(國民黨候選人得票數),
投票數 = as.numeric(投票數),
選舉人數 = as.numeric(選舉人數)) %>%
select(選舉年份, 縣市別, 行政區別, 里別, 國民黨候選人, 民進黨候選人,
國民黨候選人得票數, 民進黨候選人得票數, 投票數, 選舉人數) %>%
drop_na() %>%
group_by(行政區別, 里別) %>%
mutate(國民黨候選人得票數 = sum(國民黨候選人得票數), 民進黨候選人得票數 = sum(民進黨候選人得票數),
投票數 = sum(投票數), 選舉人數 = sum(選舉人數)) %>%
distinct(行政區別, 里別, .keep_all = T) %>%
ungroup() %>%
mutate(國民黨候選人得票率 = 國民黨候選人得票數/投票數, 民進黨候選人得票率 = 民進黨候選人得票數/投票數,
`得票率差(百分點)` = (國民黨候選人得票率 - 民進黨候選人得票率)*100,
得票數差 = 國民黨候選人得票數 - 民進黨候選人得票數, 投票率 = 投票數/選舉人數,
政黨色 = if_else(得票數差 > 0, "Blue", "Green"))
write_excel_csv(taoyuan_2018, "data/2018台中市候選人得票概況(村里別)")
#台南
tainan_2018 <- read_excel("data/縣表3-1-500(臺南市).xls")
tainan_2018 %<>%
rename("行政區別" = `107年臺南市市長選舉候選人在各投開票所得票數一覽表`, "里別" = X__1,
"民進黨候選人得票數" = X__3, "國民黨候選人得票數" = X__4, "投票數" = X__11, "選舉人數" = X__15) %>%
map(~gsub('\\s+', '',x = .)) %>%
as_data_frame() %>%
mutate(選舉年份 = 2018, 縣市別 = "台南市", 國民黨候選人 = "高思博", 民進黨候選人 = "黃偉哲",
民進黨候選人得票數 = as.numeric(民進黨候選人得票數),
國民黨候選人得票數 = as.numeric(國民黨候選人得票數),
投票數 = as.numeric(投票數),
選舉人數 = as.numeric(選舉人數)) %>%
select(選舉年份, 縣市別, 行政區別, 里別, 國民黨候選人, 民進黨候選人,
國民黨候選人得票數, 民進黨候選人得票數, 投票數, 選舉人數) %>%
drop_na() %>%
group_by(行政區別, 里別) %>%
mutate(國民黨候選人得票數 = sum(國民黨候選人得票數), 民進黨候選人得票數 = sum(民進黨候選人得票數),
投票數 = sum(投票數), 選舉人數 = sum(選舉人數)) %>%
distinct(行政區別, 里別, .keep_all = T) %>%
ungroup() %>%
mutate(國民黨候選人得票率 = 國民黨候選人得票數/投票數, 民進黨候選人得票率 = 民進黨候選人得票數/投票數,
`得票率差(百分點)` = (國民黨候選人得票率 - 民進黨候選人得票率)*100,
得票數差 = 國民黨候選人得票數 - 民進黨候選人得票數, 投票率 = 投票數/選舉人數,
政黨色 = if_else(得票數差 > 0, "Blue", "Green"))
write_excel_csv(taoyuan_2018, "data/2018台南市候選人得票概況(村里別)")
#高雄
kaoshung_2018 <- read_excel("data/縣表3-1-600(高雄市).xls")
kaoshung_2018 %<>%
rename("行政區別" = `107年高雄市市長選舉候選人在各投開票所得票數一覽表`, "里別" = X__1,
"民進黨候選人得票數" = X__4, "國民黨候選人得票數" = X__3, "投票數" = X__9, "選舉人數" = X__13) %>%
# delete the white space for further use
# map function shortcut with ~
map(~gsub('\\s+', '',x = .)) %>%
as_data_frame() %>%
mutate(選舉年份 = 2018, 縣市別 = "高雄市", 國民黨候選人 = "韓國瑜", 民進黨候選人 = "陳其邁",
民進黨候選人得票數 = as.numeric(民進黨候選人得票數),
國民黨候選人得票數 = as.numeric(國民黨候選人得票數),
投票數 = as.numeric(投票數),
選舉人數 = as.numeric(選舉人數)) %>%
select(選舉年份, 縣市別, 行政區別, 里別, 國民黨候選人, 民進黨候選人,
國民黨候選人得票數, 民進黨候選人得票數, 投票數, 選舉人數) %>%
drop_na() %>%
group_by(行政區別, 里別) %>%
mutate(國民黨候選人得票數 = sum(國民黨候選人得票數), 民進黨候選人得票數 = sum(民進黨候選人得票數),
投票數 = sum(投票數), 選舉人數 = sum(選舉人數)) %>%
distinct(行政區別, 里別, .keep_all = T) %>%
ungroup() %>%
mutate(國民黨候選人得票率 = 國民黨候選人得票數/投票數, 民進黨候選人得票率 = 民進黨候選人得票數/投票數,
`得票率差(百分點)` = (國民黨候選人得票率 - 民進黨候選人得票率)*100,
得票數差 = 國民黨候選人得票數 - 民進黨候選人得票數, 投票率 = 投票數/選舉人數,
政黨色 = if_else(得票數差 > 0, "Blue", "Green"))
write_excel_csv(taoyuan_2018, "data/2018高雄市候選人得票概況(村里別)")
```
```{r data import}
taipei_2010 <- read_excel("data/近3屆六都縣市長候選人得票概況(村里別).xlsx", sheet = "2010台北")
taipei_2014 <- read_excel("data/近3屆六都縣市長候選人得票概況(村里別).xlsx", sheet = "2014台北")
newtaipei_2010 <- read_excel("data/近3屆六都縣市長候選人得票概況(村里別).xlsx", sheet = "2010新北") %>%
mutate(選舉年份 = as.numeric(選舉年份))
newtaipei_2014 <- read_excel("data/近3屆六都縣市長候選人得票概況(村里別).xlsx", sheet = "2014新北")
taoyuan_2009 <- read_excel("data/近3屆六都縣市長候選人得票概況(村里別).xlsx", sheet = "2009桃園")
taoyuan_2014 <- read_excel("data/近3屆六都縣市長候選人得票概況(村里別).xlsx", sheet = "2014桃園")
taichung_2010 <- read_excel("data/近3屆六都縣市長候選人得票概況(村里別).xlsx", sheet = "2010台中")
taichung_2014 <- read_excel("data/近3屆六都縣市長候選人得票概況(村里別).xlsx", sheet = "2014台中")
tainan_2010 <- read_excel("data/近3屆六都縣市長候選人得票概況(村里別).xlsx", sheet = "2010台南")
tainan_2014 <- read_excel("data/近3屆六都縣市長候選人得票概況(村里別).xlsx", sheet = "2014台南")
kaoshung_2010 <- read_excel("data/近3屆六都縣市長候選人得票概況(村里別).xlsx", sheet = "2010高雄")
kaoshung_2014 <- read_excel("data/近3屆六都縣市長候選人得票概況(村里別).xlsx", sheet = "2014高雄")
```
```{r turnout 2010 and 2014}
turnout <- function(path){
t_2010 <- read_excel(path = path, skip = 1) %>%
rename(投票數 = `C
投票數
C=A+B`,
選舉人數 = `G
選舉人數
(原領票數)
G=E+F`) %>%
select(行政區別, 里別, 投票數, 選舉人數) %>%
map(~gsub('\\s+', '',x = .)) %>%
as_data_frame() %>%
mutate(投票數 = as.numeric(投票數), 選舉人數 = as.numeric(選舉人數)) %>%
drop_na() %>%
group_by(行政區別, 里別) %>%
mutate(投票數 = sum(投票數), 選舉人數 = sum(選舉人數)) %>%
distinct(行政區別, 里別, .keep_all = T) %>%
ungroup() %>%
mutate(投票率 = 投票數/選舉人數)
return(t_2010)
}
turnout_taipei_2010 <- turnout(path = "data/市表3-1-100(10臺北市).xls")
turnout_newtaipei_2010 <- turnout(path = "data/市表3-1-200(10新北市).xls")
turnout_taichung_2010 <- turnout(path = "data/市表3-1-300(10臺中市).xls")
turnout_tainan_2010 <- turnout(path = "data/市表3-1-400(10臺南市).xls")
turnout_kaoshung_2010 <- turnout(path = "data/市表3-1-500(10高雄市).xls")
turnout_taipei_2014 <- turnout(path = "data/縣表3-1-100(14臺北市)-候選人得票數一覽表.xls")
turnout_newtaipei_2014 <- turnout(path = "data/縣表3-1-200(14新北市)-候選人得票數一覽表.xls")
turnout_taoyuan_2014 <- turnout(path = "data/縣表3-1-300(14桃園市)-候選人得票數一覽表.xls")
turnout_taichung_2014 <- turnout(path = "data/縣表3-1-400(14臺中市)-候選人得票數一覽表.xls")
turnout_tainan_2014 <- turnout(path = "data/縣表3-1-500(14臺南市)-候選人得票數一覽表.xls")
turnout_kaoshung_2014 <- turnout(path = "data/縣表3-1-600(14高雄市)-候選人得票數一覽表.xls")
turnout_taoyuan_2010 <- read_excel("data/縣表3-1-303(09桃園縣).xls", skip = 1) %>%
rename(投票數 = `C
投票數
C=A+B`,
選舉人數 = `G
選舉人數
(原領票數)
G=E+F` ,
行政區別 = 鄉鎮市區別, 里別 = 村里別) %>%
select(行政區別, 里別, 投票數, 選舉人數) %>%
map(~gsub('\\s+', '',x = .)) %>%
as_data_frame() %>%
mutate(投票數 = as.numeric(投票數), 選舉人數 = as.numeric(選舉人數)) %>%
drop_na() %>%
group_by(行政區別, 里別) %>%
mutate(投票數 = sum(投票數), 選舉人數 = sum(選舉人數)) %>%
distinct(行政區別, 里別, .keep_all = T) %>%
ungroup() %>%
mutate(投票率 = 投票數/選舉人數)
```
```{r combine turnout to extant data}
turnout_combination <- function(city_data, turnout_data){
x <- city_data %>%
unite(行政區別, 里別, col = "neighbor", sep = "/")
y <- turnout_data %>%
select(-投票數) %>%
unite(行政區別, 里別, col = "neighbor", sep = "/")
z <- left_join(x = x, y = y, by = "neighbor") %>%
separate(neighbor, into = c("行政區別", "里別"))
}
taipei_2010 %<>%
turnout_combination(turnout_data = turnout_taipei_2010)
taipei_2014 %<>%
turnout_combination(turnout_data = turnout_taipei_2014)
newtaipei_2010 %<>%
turnout_combination(turnout_data = turnout_newtaipei_2010)
newtaipei_2014 %<>%
turnout_combination(turnout_data = turnout_newtaipei_2014)
taoyuan_2009 %<>%
turnout_combination(turnout_data = turnout_taoyuan_2010)
taoyuan_2014 %<>%
turnout_combination(turnout_data = turnout_taoyuan_2014)
taichung_2010 %<>%
turnout_combination(turnout_data = turnout_taichung_2010)
taichung_2014 %<>%
turnout_combination(turnout_data = turnout_taichung_2014)
tainan_2010 %<>%
turnout_combination(turnout_data = turnout_tainan_2010)
tainan_2014 %<>%
turnout_combination(turnout_data = turnout_tainan_2014)
kaoshung_2010 %<>%
turnout_combination(turnout_data = turnout_kaoshung_2010)
kaoshung_2014 %<>%
turnout_combination(turnout_data = turnout_kaoshung_2014)
```
```{r combine data}
vote_combination <- function(x_2010,x_2014,x_2018){
x_2010 %<>%
select(縣市別, 行政區別, 里別, 國民黨候選人得票數, 民進黨候選人得票數, 投票數,
國民黨候選人得票率, 民進黨候選人得票率, 選舉人數, 投票率) %>%
rename(city = 縣市別, district = 行政區別, neighbor = 里別,
KMTvote_2010 = 國民黨候選人得票數, DDPvote_2010 = 民進黨候選人得票數,
ballot_2010 = 投票數, KMTrate_2010 = 國民黨候選人得票率, DDPrate_2010 = 民進黨候選人得票率,
electorate_2010 = 選舉人數, turnout_2010 = 投票率) %>%
unite(city, district, neighbor, col = "neighbor", sep = "/")
x_2014 %<>%
select(縣市別, 行政區別, 里別, 國民黨候選人得票數, 民進黨候選人得票數, 投票數,
國民黨候選人得票率, 民進黨候選人得票率, 選舉人數, 投票率) %>%
rename(city = 縣市別, district = 行政區別, neighbor = 里別,
KMTvote_2014 = 國民黨候選人得票數, DDPvote_2014 = 民進黨候選人得票數, ballot_2014 = 投票數,
KMTrate_2014 = 國民黨候選人得票率, DDPrate_2014 = 民進黨候選人得票率,
electorate_2014 = 選舉人數, turnout_2014 = 投票率) %>%
unite(city, district, neighbor, col = "neighbor", sep = "/")
x_2018 %<>%
select(縣市別, 行政區別, 里別, 國民黨候選人得票數, 民進黨候選人得票數, 投票數,
國民黨候選人得票率, 民進黨候選人得票率, 選舉人數, 投票率) %>%
rename(city = 縣市別, district = 行政區別, neighbor = 里別,
KMTvote_2018 = 國民黨候選人得票數, DDPvote_2018 = 民進黨候選人得票數, ballot_2018 = 投票數,
KMTrate_2018 = 國民黨候選人得票率, DDPrate_2018 = 民進黨候選人得票率,
electorate_2018 = 選舉人數, turnout_2018 = 投票率) %>%
unite(city, district, neighbor, col = "neighbor", sep = "/")
z <- x_2018 %>%
left_join(x_2014, by = "neighbor") %>%
left_join(x_2010, by = "neighbor") %>%
separate(neighbor, into = c("city", "district", "neighbor"))
return(z)
}
newtaipei_2010_to_2018 <- vote_combination(newtaipei_2010, newtaipei_2014, newtaipei_2018)
taoyuan_2010_to_2018 <- vote_combination(taoyuan_2009, taoyuan_2014, taoyuan_2018)
taichung_2010_to_2018 <- vote_combination(taichung_2010, taichung_2014, taichung_2018)
kaoshung_working_2010 <- kaoshung_2010 %>%
select(縣市別, 行政區別, 里別, 國民黨候選人得票數, 民進黨候選人得票數, 無黨籍候選人得票數,
投票數, 國民黨候選人得票率, 民進黨候選人得票率, 無黨籍候選人得票率, 選舉人數, 投票率) %>%
rename(city = 縣市別, district = 行政區別, neighbor = 里別,
KMTvote_2010 = 國民黨候選人得票數, DDPvote_2010 = 民進黨候選人得票數, NPvote_2010 = 無黨籍候選人得票數,
ballot_2010 = 投票數, KMTrate_2010 = 國民黨候選人得票率, DDPrate_2010 = 民進黨候選人得票率,
NPrate_2010 = 無黨籍候選人得票率,
electorate_2010 = 選舉人數, turnout_2010 = 投票率) %>%
unite(city, district, neighbor, col = "neighbor", sep = "/") # For joining the data
kaoshung_working_2014 <- kaoshung_2014 %>%
select(縣市別, 行政區別, 里別, 國民黨候選人得票數, 民進黨候選人得票數, 投票數,
國民黨候選人得票率, 民進黨候選人得票率, 選舉人數, 投票率) %>%
rename(city = 縣市別, district = 行政區別, neighbor = 里別,
KMTvote_2014 = 國民黨候選人得票數, DDPvote_2014 = 民進黨候選人得票數, ballot_2014 = 投票數,
KMTrate_2014 = 國民黨候選人得票率, DDPrate_2014 = 民進黨候選人得票率,
electorate_2014 = 選舉人數, turnout_2014 = 投票率) %>%
unite(city, district, neighbor, col = "neighbor", sep = "/")
kaoshung_working_2018 <- kaoshung_2018 %>%
select(縣市別, 行政區別, 里別, 國民黨候選人得票數, 民進黨候選人得票數, 投票數,
國民黨候選人得票率, 民進黨候選人得票率, 選舉人數, 投票率) %>%
rename(city = 縣市別, district = 行政區別, neighbor = 里別,
KMTvote_2018 = 國民黨候選人得票數, DDPvote_2018 = 民進黨候選人得票數, ballot_2018 = 投票數,
KMTrate_2018 = 國民黨候選人得票率, DDPrate_2018 = 民進黨候選人得票率,
electorate_2018 = 選舉人數, turnout_2018 = 投票率) %>%
unite(city, district, neighbor, col = "neighbor", sep = "/")
kaoshung_2010_to_2018 <- kaoshung_working_2018 %>%
left_join(kaoshung_working_2014, by = "neighbor") %>%
left_join(kaoshung_working_2010, by = "neighbor") %>%
separate(neighbor, into = c("city", "district", "neighbor"))
taipei_working_2010 <- taipei_2010 %>%
select(縣市別, 行政區別, 里別, 國民黨候選人得票數, 民進黨候選人得票數, 投票數,
國民黨候選人得票率, 民進黨候選人得票率, 選舉人數, 投票率) %>%
rename(city = 縣市別, district = 行政區別, neighbor = 里別,
KMTvote_2010 = 國民黨候選人得票數, DDPvote_2010 = 民進黨候選人得票數, ballot_2010 = 投票數,
KMTrate_2010 = 國民黨候選人得票率, DDPrate_2010 = 民進黨候選人得票率,
electorate_2010 = 選舉人數, turnout_2010 = 投票率) %>%
unite(city, district, neighbor, col = "neighbor", sep = "/")
taipei_working_2014 <- taipei_2014 %>%
select(縣市別, 行政區別, 里別, 國民黨候選人得票數, 無黨籍候選人得票數,
投票數, 國民黨候選人得票率, 無黨籍候選人得票率, 選舉人數, 投票率) %>%
rename(city = 縣市別, district = 行政區別, neighbor = 里別,
KMTvote_2014 = 國民黨候選人得票數, NPvote_2014 = 無黨籍候選人得票數, ballot_2014 = 投票數,
KMTrate_2014 = 國民黨候選人得票率, NPrate_2014 = 無黨籍候選人得票率,
electorate_2014 = 選舉人數, turnout_2014 = 投票率) %>%
unite(city, district, neighbor, col = "neighbor", sep = "/")
taipei_working_2018 <- taipei_2018 %>%
select(縣市別, 行政區別, 里別, 國民黨候選人得票數, 民進黨候選人得票數, 無黨籍候選人得票數,
投票數, 國民黨候選人得票率, 民進黨候選人得票率, 無黨籍候選人得票率, 選舉人數, 投票率) %>%
rename(city = 縣市別, district = 行政區別, neighbor = 里別,
KMTvote_2018 = 國民黨候選人得票數, DDPvote_2018 = 民進黨候選人得票數, NPvote_2018 = 無黨籍候選人得票數,
ballot_2018 = 投票數, KMTrate_2018 = 國民黨候選人得票率, DDPrate_2018 = 民進黨候選人得票率,
NPrate_2018 = 無黨籍候選人得票率,
electorate_2018 = 選舉人數, turnout_2018 = 投票率) %>%
unite(city, district, neighbor, col = "neighbor", sep = "/")
taipei_2010_to_2018 <- taipei_working_2010 %>%
left_join(taipei_working_2014, by = "neighbor") %>%
left_join(taipei_working_2018, by = "neighbor") %>%
separate(neighbor, into = c("city", "district", "neighbor"))
taiwan_2010_to_2018 <- bind_rows(taipei_2010_to_2018, newtaipei_2010_to_2018,
taoyuan_2010_to_2018, taichung_2010_to_2018,
kaoshung_2010_to_2018) #台南2018年村里重劃,無法放在一起看
write_excel_csv(taiwan_2010_to_2018, "data/台灣六都(台南除外)2010至18年市長選舉結果(村里別)")
taiwan_2018 <- bind_rows(taipei_2018, newtaipei_2018, taoyuan_2018, taichung_2018, tainan_2018, kaoshung_2018)
taiwan_2014 <- bind_rows(taipei_2014, newtaipei_2014, taoyuan_2014, taichung_2014, tainan_2014, kaoshung_2014)
taiwan_2010 <- bind_rows(taipei_2010, newtaipei_2010, taoyuan_2009, taichung_2010, tainan_2010, kaoshung_2010)
```
```{r mutate data}
taiwan_2010_to_2018 %<>%
mutate(KMTrsp_2010 = KMTvote_2010/electorate_2010, DDPrsp_2010 = DDPvote_2010/electorate_2010,
NPrsp_2010 = NPvote_2010/electorate_2010, KMTrsp_2014 = KMTvote_2014/electorate_2014,
DDPrsp_2014 = DDPvote_2014/electorate_2014, NPrsp_2014 = NPvote_2014/electorate_2014,
KMTrsp_2018 = KMTvote_2018/electorate_2018, DDPrsp_2018 = DDPvote_2018/electorate_2018,
NPrsp_2018 = NPvote_2018/electorate_2018,
ballot_10_to_14 = ballot_2014 - ballot_2010, ballot_14_to_18 = ballot_2018 - ballot_2014,
turnout_10_to_14 = turnout_2014 - turnout_2010, turnout_14_to_18 = turnout_2018 - turnout_2014,
DDPvote_10_to_14 = DDPvote_2014 - DDPvote_2010, DDPvote_14_to_18 = DDPvote_2018 - DDPvote_2014,
KMTvote_10_to_14 = KMTvote_2014 - KMTvote_2010, KMTvote_14_to_18 = KMTvote_2018 - KMTvote_2014,
NPvote_10_to_14 = NPvote_2014 - NPvote_2010, NPvote_14_to_18 = NPvote_2018 - NPvote_2014,
DDPrate_10_to_14 = DDPrate_2014 - DDPrate_2010, DDPrate_14_to_18 = DDPrate_2018 - DDPrate_2014,
KMTrate_10_to_14 = KMTrate_2014 - KMTrate_2010, KMTrate_14_to_18 = KMTrate_2018 - KMTrate_2014,
NPrate_10_to_14 = NPrate_2014 - NPrate_2010, NPrate_14_to_18 = NPrate_2018 - NPrate_2014,
DDPrsp_10_to_14 = DDPrsp_2014 - DDPrsp_2010, DDPrsp_14_to_18 = DDPrsp_2018 - DDPrsp_2014,
KMTrsp_10_to_14 = KMTrsp_2014 - KMTrsp_2010, KMTrsp_14_to_18 = KMTrsp_2018 - KMTrsp_2014,
NPrsp_10_to_14 = NPrsp_2014 - NPrsp_2010, NPrsp_14_to_18 = NPrsp_2018 - NPrsp_2014)
```
```{r 2014 turnout and voting pattern ballot}
#投票數基本圖像 14
taiwan_2010_to_2018 %>%
ggplot(aes(x = ballot_2010)) + geom_point(aes(y = ballot_2014), color = "red", alpha = 0.1) +
geom_point(aes(y = ballot_2018), color = "yellow", alpha = 0.1) + geom_abline() +
labs(title = "投票數", x = "2010年各里投票數", y = "14(紅)及18年(黃)投票數") +
theme(text = element_text(family = "Heiti TC Light")) # 指定繁體中文黑體
#投票數變化與票數 14
taiwan_2010_to_2018 %>%
filter(city != "台北市") %>%
ggplot(aes(x = ballot_10_to_14)) +
geom_point(aes(y = KMTvote_2014), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = KMTvote_2014), color = "blue", method = "lm", alpha = 0.4 ) +
geom_point(aes(y = DDPvote_2014), color = "green", alpha = 0.3) +
geom_smooth(aes(y = DDPvote_2014), color = "green", method = "lm", alpha = 0.4) +
labs(title = "14年投票人數變化與票數", x = "10-14 投票人數變化", y = "票數") +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2010_to_2018 %>%
filter(city == "台北市") %>%
ggplot(aes(x = ballot_10_to_14)) +
geom_point(aes(y = KMTvote_2014), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = KMTvote_2014), color = "blue", method = "lm", alpha = 0.4) +
geom_point(aes(y = NPvote_2014), color = "green", alpha = 0.3) +
geom_smooth(aes(y = NPvote_2014), color = "green", method = "lm", alpha = 0.4) +
labs(title = "14年投票人數變化與票數(台北市)", x = "10-14 投票人數變化", y = "票數") +
theme(text = element_text(family = "Heiti TC Light"))
#投票數變化與票數變化
taiwan_2010_to_2018 %>%
filter(city != c("台北市", "高雄市")) %>%
ggplot(aes(x = ballot_10_to_14)) +
geom_point(aes(y = KMTvote_10_to_14), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = KMTvote_10_to_14), color = "blue", method = "lm", alpha = 0.4 ) +
geom_point(aes(y = DDPvote_10_to_14), color = "green", alpha = 0.3) +
geom_smooth(aes(y = DDPvote_10_to_14), color = "green", method = "lm", alpha = 0.4) +
labs(title = "14年投票人數變化與票數變化", x = "10-14 投票人數變化", y = "票數") +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2010_to_2018 %>%
filter(city == "台北市") %>% #14柯文哲減去10蘇貞昌
ggplot(aes(x = ballot_10_to_14)) +
geom_point(aes(y = KMTvote_10_to_14), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = KMTvote_10_to_14), color = "blue", method = "lm", alpha = 0.4) +
geom_point(aes(y = (NPvote_2014 - DDPvote_2010)), color = "green", alpha = 0.3) +
geom_smooth(aes(y = (NPvote_2014 - DDPvote_2010)), color = "green", method = "lm", alpha = 0.4) +
labs(title = "14年投票人數變化與票數變化(台北市)", x = "10-14 投票人數變化", y = "票數") +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2010_to_2018 %>% #14楊秋興減去10黃昭順與楊秋興
filter(city == "高雄市") %>%
ggplot(aes(x = ballot_10_to_14)) +
geom_point(aes(y = (KMTvote_10_to_14 - NPvote_2010)), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = (KMTvote_10_to_14 - NPvote_2010)), color = "blue", method = "lm", alpha = 0.4) +
geom_point(aes(y = DDPvote_10_to_14), color = "green", alpha = 0.3) +
geom_smooth(aes(y = DDPvote_10_to_14), color = "green", method = "lm", alpha = 0.4) +
labs(title = "14年投票人數變化與票數變化(高雄市)", x = "10-14 投票人數變化", y = "票數") +
theme(text = element_text(family = "Heiti TC Light"))
```
```{r 2014 turnout and voting rate}
#投票率圖像
taiwan_2010_to_2018 %>%
ggplot(aes(x = turnout_2010)) + geom_point(aes(y = turnout_2014), color = "red", alpha = 0.1) +
geom_point(aes(y = turnout_2018), color = "yellow", alpha = 0.1) + geom_abline() +
labs(title = "投票率", x = "2010年各里投票率", y = "14(紅)及18年(黃)投票率") +
theme(text = element_text(family = "Heiti TC Light")) # 指定繁體中文黑體
#投票率與得票率
taiwan_2014 %>%
filter(縣市別 != c("台北市")) %>%
ggplot(aes(x = 投票率)) +
geom_point(aes(y = 國民黨候選人得票率), color = "blue", alpha = 0.2 ) +
geom_smooth(aes(y = 國民黨候選人得票率), color = "blue", method = "lm", alpha = 0.3) +
geom_point(aes(y = 民進黨候選人得票率), color = "green", alpha = 0.2 ) +
geom_smooth(aes(y = 民進黨候選人得票率), color = "green", method = "lm", alpha = 0.3) +
labs(title = "2014年投票率與得票率", x = "投票率", y = "得票率") +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2014 %>%
filter(縣市別 == "台北市") %>%
ggplot(aes(x = 投票率)) +
geom_point(aes(y = 國民黨候選人得票率), color = "blue", alpha = 0.2 ) +
geom_smooth(aes(y = 國民黨候選人得票率), color = "blue", method = "lm", alpha = 0.3) +
geom_point(aes(y = 無黨籍候選人得票率), color = "green", alpha = 0.2 ) +
geom_smooth(aes(y = 無黨籍候選人得票率), color = "green", method = "lm", alpha = 0.3) +
labs(title = "2014年投票率與得票率(台北市)", x = "投票率", y = "得票率") +
theme(text = element_text(family = "Heiti TC Light"))
#投票率變化與得票率
taiwan_2010_to_2018 %>%
filter(city != "台北市") %>%
ggplot(aes(x = turnout_10_to_14)) +
geom_point(aes(y = KMTrate_2014), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = KMTrate_2014), color = "blue", method = "lm", alpha = 0.4 ) +
geom_point(aes(y = DDPrate_2014), color = "green", alpha = 0.3) +
geom_smooth(aes(y = DDPrate_2014), color = "green", method = "lm", alpha = 0.4) +
labs(title = "14年投票率變化與得票率", x = "10-14 投票率變化", y = "14年得票率") +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2010_to_2018 %>%
filter(city == "台北市") %>%
ggplot(aes(x = turnout_10_to_14)) +
geom_point(aes(y = KMTrate_2014), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = KMTrate_2014), color = "blue", method = "lm", alpha = 0.4) +
geom_point(aes(y = NPrate_2014), color = "green", alpha = 0.3) +
geom_smooth(aes(y = NPrate_2014), color = "green", method = "lm", alpha = 0.4) +
labs(title = "14年投票率變化與得票率(台北市)", x = "10-14 投票率變化", y = "14得票率") +
theme(text = element_text(family = "Heiti TC Light"))
#投票率變化與得票率變化
taiwan_2010_to_2018 %>%
filter(city != c("台北市", "高雄市")) %>%
ggplot(aes(x = turnout_10_to_14)) +
geom_point(aes(y = KMTrate_10_to_14), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = KMTrate_10_to_14), color = "blue", method = "lm", alpha = 0.4 ) +
geom_point(aes(y = DDPrate_10_to_14), color = "green", alpha = 0.3) +
geom_smooth(aes(y = DDPrate_10_to_14), color = "green", method = "lm", alpha = 0.4) +
labs(title = "14年投票率變化與得票率變化", x = "10-14 投票率變化", y = "得票率變化") +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2010_to_2018 %>%
filter(city == "台北市") %>% #14柯文哲減去10蘇貞昌
ggplot(aes(x = turnout_10_to_14)) +
geom_point(aes(y = KMTrate_10_to_14), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = KMTrate_10_to_14), color = "blue", method = "lm", alpha = 0.4) +
geom_point(aes(y = (NPrate_2014 - DDPrate_2010)), color = "green", alpha = 0.3) +
geom_smooth(aes(y = (NPrate_2014 - DDPrate_2010)), color = "green", method = "lm", alpha = 0.4) +
labs(title = "14年投票率變化與得票率變化(台北市)", x = "10-14 投票率變化", y = "得票率變化") +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2010_to_2018 %>% #14楊秋興減去10黃昭順與楊秋興
filter(city == "高雄市") %>%
ggplot(aes(x = turnout_10_to_14)) +
geom_point(aes(y = (KMTrate_10_to_14 - NPrate_2010)), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = (KMTrate_10_to_14 - NPrate_2010)), color = "blue", method = "lm", alpha = 0.4) +
geom_point(aes(y = DDPrate_10_to_14), color = "green", alpha = 0.3) +
geom_smooth(aes(y = DDPrate_10_to_14), color = "green", method = "lm", alpha = 0.4) +
labs(title = "14年投票率變化與得票率變化(高雄市)", x = "10-14 投票率變化", y = "得票率變化") +
theme(text = element_text(family = "Heiti TC Light"))
```
```{r 2018 turnout and voting pattern}
#投票率與得票率
taiwan_2018 %>%
filter(縣市別 != c("台北市")) %>%
ggplot(aes(x = 投票率)) +
geom_point(aes(y = 國民黨候選人得票率), color = "blue", alpha = 0.2 ) +
geom_smooth(aes(y = 國民黨候選人得票率), color = "blue", method = "lm", alpha = 0.3) +
geom_point(aes(y = 民進黨候選人得票率), color = "green", alpha = 0.2 ) +
geom_smooth(aes(y = 民進黨候選人得票率), color = "green", method = "lm", alpha = 0.3) +
labs(title = "2018年投票率與得票率", x = "投票率", y = "得票率") +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2018 %>%
filter(縣市別 == "台北市") %>%
ggplot(aes(x = 投票率)) +
geom_point(aes(y = 國民黨候選人得票率), color = "blue", alpha = 0.2 ) +
geom_smooth(aes(y = 國民黨候選人得票率), color = "blue", method = "lm", alpha = 0.3) +
geom_point(aes(y = 無黨籍候選人得票率), color = "red", alpha = 0.2 ) +
geom_smooth(aes(y = 無黨籍候選人得票率), color = "red", method = "lm", alpha = 0.3) +
geom_point(aes(y = 民進黨候選人得票率), color = "green", alpha = 0.2 ) +
geom_smooth(aes(y = 民進黨候選人得票率), color = "green", method = "lm", alpha = 0.3) +
labs(title = "2018年投票率與得票率(台北市)", x = "投票率", y = "得票率") +
theme(text = element_text(family = "Heiti TC Light"))
#投票率變化與得票率
taiwan_2010_to_2018 %>%
filter(city != "台北市") %>%
ggplot(aes(x = turnout_14_to_18)) +
geom_point(aes(y = KMTrate_2018), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = KMTrate_2018), color = "blue", method = "lm", alpha = 0.4 ) +
geom_point(aes(y = DDPrate_2018), color = "green", alpha = 0.3) +
geom_smooth(aes(y = DDPrate_2018), color = "green", method = "lm", alpha = 0.4) +
labs(title = "18年投票率變化與得票率", x = "14-18 投票率變化", y = "18年得票率") +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2010_to_2018 %>%
filter(city == "台北市") %>%
ggplot(aes(x = turnout_10_to_14)) +
geom_point(aes(y = KMTrate_2018), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = KMTrate_2018), color = "blue", method = "lm", alpha = 0.4) +
geom_point(aes(y = DDPrate_2018), color = "green", alpha = 0.3) +
geom_smooth(aes(y = DDPrate_2018), color = "green", method = "lm", alpha = 0.4) +
geom_point(aes(y = NPrate_2018), color = "red", alpha = 0.3) +
geom_smooth(aes(y = NPrate_2018), color = "red", method = "lm", alpha = 0.4) +
labs(title = "18年投票率變化與得票率(台北市)", x = "14-18 投票率變化", y = "18得票率") +
theme(text = element_text(family = "Heiti TC Light"))
#投票率變化與得票率變化
taiwan_2010_to_2018 %>%
filter(city != "台北市") %>%
ggplot(aes(x = turnout_14_to_18)) +
geom_point(aes(y = KMTrate_14_to_18), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = KMTrate_14_to_18), color = "blue", method = "lm", alpha = 0.4 ) +
geom_point(aes(y = DDPrate_14_to_18), color = "green", alpha = 0.3) +
geom_smooth(aes(y = DDPrate_14_to_18), color = "green", method = "lm", alpha = 0.4) +
labs(title = "18年投票率變化與得票率變化", x = "14-18 投票率變化", y = "得票率變化") +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2010_to_2018 %>%
filter(city == "台北市") %>% #18柯文哲跟姚文智算一起
ggplot(aes(x = turnout_14_to_18)) +
geom_point(aes(y = KMTrate_14_to_18), color = "blue", alpha = 0.3) +
geom_smooth(aes(y = KMTrate_14_to_18), color = "blue", method = "lm", alpha = 0.4) +
geom_point(aes(y = (NPrate_14_to_18 + DDPrate_2018)), color = "green", alpha = 0.3) +
geom_smooth(aes(y = (NPrate_14_to_18 + DDPrate_2018)), color = "green", method = "lm", alpha = 0.4) +
labs(title = "18年投票率變化與得票率變化(台北市)", x = "14-18 投票率變化", y = "得票率變化") +
theme(text = element_text(family = "Heiti TC Light"))
```
```{r 2014 vote change and 2018 vote change}
taiwan_2010_to_2018 %>%
filter(city == "台北市") %>%
ggplot() +
geom_point(aes(x = KMTrate_10_to_14, y = KMTrate_14_to_18), color = "blue", alpha = 0.2) +
geom_smooth(aes(x = KMTrate_10_to_14, y = KMTrate_14_to_18), color = "blue", method = "lm", alpha = 0.2) +
geom_point(aes(x = (NPrate_2014 - DDPrate_2010), y = (NPrate_14_to_18 + DDPrate_2018)),
color = "green", alpha = 0.2) +
geom_smooth(aes(x = (NPrate_2014 - DDPrate_2010), y = (NPrate_14_to_18 + DDPrate_2018)),
color = "green", method = "lm", alpha = 0.2) +
labs(title = "台北三屆選舉得票率變化", x = "10-14年得票率變化", y = "14-18年得票率變化") +
expand_limits(x = c(-0.3, 0.3), y = c(-0.3, 0.3)) +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2010_to_2018 %>%
filter(city == "新北市") %>%
ggplot() +
geom_point(aes(x = KMTrate_10_to_14, y = KMTrate_14_to_18), color = "blue", alpha = 0.2) +
geom_smooth(aes(x = KMTrate_10_to_14, y = KMTrate_14_to_18), color = "blue", method = "lm", alpha = 0.2) +
geom_point(aes(x = DDPrate_10_to_14, y = DDPrate_14_to_18), color = "green", alpha = 0.2) +
geom_smooth(aes(x = DDPrate_10_to_14, y = DDPrate_14_to_18), color = "green", method = "lm", alpha = 0.2) +
labs(title = "新北三屆選舉得票率變化", x = "10-14年得票率變化", y = "14-18年得票率變化") +
expand_limits(x = c(-0.3, 0.3), y = c(-0.3, 0.3)) +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2010_to_2018 %>%
filter(city == "桃園市") %>%
ggplot() +
geom_point(aes(x = KMTrate_10_to_14, y = KMTrate_14_to_18), color = "blue", alpha = 0.2) +
geom_smooth(aes(x = KMTrate_10_to_14, y = KMTrate_14_to_18), color = "blue", method = "lm", alpha = 0.2) +
geom_point(aes(x = DDPrate_10_to_14, y = DDPrate_14_to_18), color = "green", alpha = 0.2) +
geom_smooth(aes(x = DDPrate_10_to_14, y = DDPrate_14_to_18), color = "green", method = "lm", alpha = 0.2) +
labs(title = "桃園三屆選舉得票率變化", x = "10-14年得票率變化", y = "14-18年得票率變化") +
expand_limits(x = c(-0.3, 0.3), y = c(-0.3, 0.3)) +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2010_to_2018 %>%
filter(city == "台中市") %>%
ggplot() +
geom_point(aes(x = KMTrate_10_to_14, y = KMTrate_14_to_18), color = "blue", alpha = 0.2) +
geom_smooth(aes(x = KMTrate_10_to_14, y = KMTrate_14_to_18), color = "blue", method = "lm", alpha = 0.2) +
geom_point(aes(x = DDPrate_10_to_14, y = DDPrate_14_to_18), color = "green", alpha = 0.2) +
geom_smooth(aes(x = DDPrate_10_to_14, y = DDPrate_14_to_18), color = "green", method = "lm", alpha = 0.2) +
labs(title = "台中三屆選舉得票率變化", x = "10-14年得票率變化", y = "14-18年得票率變化") +
expand_limits(x = c(-0.3, 0.3), y = c(-0.3, 0.3)) +
theme(text = element_text(family = "Heiti TC Light"))
taiwan_2010_to_2018 %>%
filter(city == "高雄市") %>%
ggplot() +
geom_point(aes(x = (KMTrate_10_to_14 - NPrate_2010), y = KMTrate_14_to_18), color = "blue", alpha = 0.2) +
geom_smooth(aes(x = (KMTrate_10_to_14 - NPrate_2010), y = KMTrate_14_to_18), color = "blue",
method = "lm", alpha = 0.2) +
geom_point(aes(x = DDPrate_10_to_14, y = DDPrate_14_to_18), color = "green", alpha = 0.2) +
geom_smooth(aes(x = DDPrate_10_to_14, y = DDPrate_14_to_18), color = "green", method = "lm", alpha = 0.2) +
labs(title = "高雄三屆選舉得票率變化", x = "10-14年得票率變化", y = "14-18年得票率變化") +
expand_limits(x = c(-0.3, 0.3), y = c(-0.3, 0.3)) +
theme(text = element_text(family = "Heiti TC Light"))
```