forked from ElectProject/Early-Vote-2020G
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSC.Rmd
197 lines (150 loc) · 6.8 KB
/
SC.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
---
title: "South Carolina Early Voting Statistics"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(knitr)
library(kableExtra)
library(scales)
state_stats <- read_csv("D:/DropBox/Dropbox/Mail_Ballots_2020/markdown/2020G_Early_Vote.csv")
SC_stats <- read_csv("D:/DropBox/Dropbox/Mail_Ballots_2020/markdown/2020G_Early_Vote_SC.csv")
# Setup
party_shell <- data.frame(Party=character(),
Count=integer(),
Percent=double(),
stringsAsFactors=FALSE)
party_shell[1,1] <- "Democrats"
party_shell[2,1] <- "Republicans"
party_shell[3,1] <- "Minor"
party_shell[4,1] <- "No Party Affiliation"
party_shell[5,1] <- "TOTAL"
race_shell <- data.frame(Race=character(),
Count=integer(),
Percent=double(),
stringsAsFactors=FALSE)
race_shell[1,1] <- "Non-Hispanic White"
race_shell[2,1] <- "Non-Hispanic Black"
race_shell[3,1] <- "Hispanic"
race_shell[4,1] <- "Non-Hispanic Asian American"
race_shell[5,1] <- "Non-Hispanic Native American"
race_shell[6,1] <- "Other/Multiple/Unknown"
race_shell[7,1] <- "TOTAL"
gender_shell <- data.frame(Gender=character(),
Count=integer(),
Percent=double(),
stringsAsFactors=FALSE)
gender_shell[1,1] <- "Female"
gender_shell[2,1] <- "Male"
gender_shell[3,1] <- "Unknown"
gender_shell[4,1] <- "TOTAL"
age_shell <- data.frame(Age=character(),
Count=integer(),
Percent=double(),
stringsAsFactors=FALSE)
age_shell[1,1] <- "18 to 24"
age_shell[2,1] <- "25 to 34"
age_shell[3,1] <- "35 to 44"
age_shell[4,1] <- "45 to 54"
age_shell[5,1] <- "55 to 64"
age_shell[6,1] <- "65 and up"
age_shell[7,1] <- "TOTAL"
# South Carolina
SC_req_send_race <- race_shell
SC_req_send_race[1,2] <- sum(state_stats[41,14])
SC_req_send_race[2,2] <- sum(state_stats[41,15])
SC_req_send_race[3,2] <- sum(state_stats[41,16])
SC_req_send_race[4,2] <- sum(state_stats[41,17])
SC_req_send_race[5,2] <- sum(state_stats[41,18])
SC_req_send_race[6,2] <- sum(state_stats[41,19])
SC_req_send_race[7,2] <- sum(state_stats[41,5])
SC_req_send_race$Percent <- 100 * SC_req_send_race$Count/SC_req_send_race[7,2]
race_shell_returned <- data.frame(Race=character(),
Count=integer(),
Frequency=double(),
Count2=integer(),
Rate=integer(),
stringsAsFactors=FALSE)
race_shell_returned[1,1] <- "Non-Hispanic White"
race_shell_returned[2,1] <- "Non-Hispanic Black"
race_shell_returned[3,1] <- "Hispanic"
race_shell_returned[4,1] <- "Non-Hispanic Asian American"
race_shell_returned[5,1] <- "Non-Hispanic Native American"
race_shell_returned[6,1] <- "Other/Multiple/Unknown"
race_shell_returned[7,1] <- "TOTAL"
SC_accept_race <- race_shell_returned
SC_accept_race[1,2] <- sum(state_stats[41,33])
SC_accept_race[2,2] <- sum(state_stats[41,34])
SC_accept_race[3,2] <- sum(state_stats[41,37])
SC_accept_race[4,2] <- sum(state_stats[41,35])
SC_accept_race[5,2] <- sum(state_stats[41,36])
SC_accept_race[6,2] <- sum(state_stats[41,38])
SC_accept_race[7,2] <- sum(state_stats[41,6])
SC_accept_race[1,4] <- sum(state_stats[41,14])
SC_accept_race[2,4] <- sum(state_stats[41,15])
SC_accept_race[3,4] <- sum(state_stats[41,16])
SC_accept_race[4,4] <- sum(state_stats[41,17])
SC_accept_race[5,4] <- sum(state_stats[41,18])
SC_accept_race[6,4] <- sum(state_stats[41,19])
SC_accept_race[7,4] <- sum(state_stats[41,5])
SC_accept_race$Frequency <- 100 * SC_accept_race$Count/SC_accept_race[7,2]
SC_accept_race$Rate <- 100*SC_accept_race$Count/SC_accept_race$Count2
colnames(SC_accept_race) <- c("Race/Ethnicity", "Returned Ballots", "Freq. Distribution", "Requested Ballots", "Return Rate")
SC_stats_requests <- select(SC_stats, County, Reg.Voters, Mail.Req.Tot)
SC_stats_requests <- mutate(SC_stats_requests, Pct.Request = Mail.Req.Tot/Reg.Voters)
SC_stats_returns <- select(SC_stats, County, Mail.Req.Tot, Mail.Rtn.Tot)
SC_stats_returns <- mutate(SC_stats_returns, Pct.Return = Mail.Rtn.Tot/Mail.Req.Tot)
```
## {.tabset}
Last Report: `r state_stats[41,9]`
Source: `r state_stats[41,2]`
South Carolina does not have party registration, but does provides ballot counts by race.
### Mail Ballots Returned
Ballots Returned: **`r format(as.numeric(state_stats[41,6]), big.mark =",")`**
#### Mail Ballots Returned and Accepted by Race and Ethnicity
``` {r echo = FALSE}
kable(SC_accept_race, format.args = list(big.mark = ",",
scientific = FALSE), digits = 1) %>%
kable_styling(bootstrap_options = "striped", full_width = F, position = "left")
```
``` {r echo = FALSE}
SC_map_data <- SC_stats
SC_map_data <- mutate(SC_map_data, percent = round(100*(Mail.Rtn.Tot/Mail.Req.Tot), digits = 1))
SC_map_data <- mutate(SC_map_data, fips = as.character(fips))
mapfile <- download_map_data("countries/us/us-sc-all.js")
mapdata <- get_data_from_map(mapfile)
mapdata$row <- as.integer(rownames(mapdata))
SC_map_data <- left_join(SC_map_data, mapdata, by = "fips")
SC_map_data <- arrange(SC_map_data, row)
hcmap(map = "countries/us/us-sc-all", data = SC_map_data,
value = "percent", name = "Percent Returned", joinBy = "fips")
```
``` {r echo = FALSE}
datatable(SC_stats_returns, colnames = c("County", "Mail Ballots Requested", "Mail Ballot Returned", "Percent Returned"), rownames = F) %>%
formatPercentage('Pct.Return', 1) %>%
formatRound(c('Mail.Req.Tot','Mail.Rtn.Tot'), 0, mark = ",")
```
### Mail Ballot Requested
#### Mail Ballots Requested by Race and Ethnicity
``` {r echo = FALSE}
kable(SC_req_send_race, format.args = list(big.mark = ",",
scientific = FALSE), digits = 1) %>%
kable_styling(bootstrap_options = "striped", full_width = F, position = "left")
```
``` {r echo = FALSE}
SC_map_data <- SC_stats
SC_map_data <- mutate(SC_map_data, percent = round(100*(Mail.Req.Tot/Reg.Voters), digits = 1))
SC_map_data <- mutate(SC_map_data, fips = as.character(fips))
mapfile <- download_map_data("countries/us/us-sc-all.js")
mapdata <- get_data_from_map(mapfile)
mapdata$row <- as.integer(rownames(mapdata))
SC_map_data <- left_join(SC_map_data, mapdata, by = "fips")
SC_map_data <- arrange(SC_map_data, row)
hcmap(map = "countries/us/us-sc-all", data = SC_map_data,
value = "percent", name = "Percent Requested", joinBy = "fips")
```
``` {r echo = FALSE}
datatable(SC_stats_requests, colnames = c("County", "Registered Voters", "Mail Ballots Requested", "Percent Requested"), rownames = F) %>%
formatPercentage('Pct.Request', 1) %>%
formatRound(c('Reg.Voters','Mail.Req.Tot'), 0, mark = ",")
```