-
Notifications
You must be signed in to change notification settings - Fork 1
/
Wisconsin Casualty Visualization in R.Rmd
188 lines (114 loc) · 4.97 KB
/
Wisconsin Casualty Visualization in R.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
---
title: "Wisconsin County Visualization in R"
author: "raymond.k.roberts@gmail.com"
date: "March 7, 2020"
output:
word_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Packages for project
```{r, message=FALSE}
require(usmap)
library(ggplot2)
require(dplyr)
require(readxl)
require(ggpubr)
```
## Download Data
The dataset being utilized I created by reading through the obituary of every US soldier that died in a combat zone for the Iraqi and Afghan wars. While the obituaries were readily available via Military.com, there was not an accessible structured data set. This required first running a query through website which presented the links, then browsing through each individually.
Wisconsin has 72 counties and a population rougly around 5.5 million, just shy of the total population of country Finland. The state is mostly rural geographically, which leads to a narrative that the state is mainly fueled and supported by rural populations. This idea extends past simply economic and political discussions and even into who is serviing the to the benefit of the state and the nation. This is an visual journey through the data using those who made the highest sacrifice as a proxy for population and culture trends.
```{r}
fallen <- read.csv("C://wifallen.csv")
fallen$fall <- ifelse(fallen$Hometown == "" , 0, 1)
```
## Aggregating Data County.
```{r}
# Data Transformation for Aggregation
A<-unique(fallen %>%
group_by(fips) %>%
mutate(number_casualties = sum(fall)) %>%
select(fips,County,number_casualties))
A <- A[order(-A$number_casualties),]
# Summary Statistics for Counties with Casualties
state_casualty_mean <- mean(A$number_casualties)
state_casualty_sum <- sum(A$number_casualties)
county_with_casualty_count <- length(A$number_casualties)
```
# True final Visualization
```{r}
#Dropping counties with no values for more dramatic demonstration
fallen2 <- read.csv("C://wifallen.csv")
fallen2$Hometown <- ifelse(fallen2$Hometown=="", NA ,fallen2$Hometown )
fallen2 <- fallen2[complete.cases(fallen2), ]
X<-unique(fallen2 %>%
group_by(fips) %>%
mutate(number_casualties = n()) %>%
select(fips,County,number_casualties))
WZmap<- usmap::plot_usmap(
data = X, values = "number_casualties", include = c("WI"), regions = "counties", color = "red"
)+
scale_fill_continuous(
low = "white", high = "red", name = "Raw Count", label = scales::comma
) +
labs(title = "Wisconsin US Service Member Casualties \n Iraq & Afghanistan",
subtitle = "Reported casualty Counts through Feb. 17, 2020 .",
caption = " Grey Counties have zero casualties ")
Mapper1 <-WZmap + theme(
plot.title = element_text(color = "red", size = 20, face = "bold",hjust = 0.45, vjust=2.12),
plot.subtitle = element_text(color = "blue",hjust = 0.75),
plot.caption = element_text(color = "black", face = "italic"),
legend.position = "right"
)
```
# Weighting by County Ratio of State Population
```{r}
fallen$Pop.Pct <- scale(fallen$Pop.Pct, center = TRUE, scale = TRUE)
X<-unique(fallen %>%
group_by(fips) %>%
mutate(number_casualties = n(),
weighted_casualties = number_casualties*(1/Pop.Pct)) %>%
select(fips,County,weighted_casualties))
WZmap<- usmap::plot_usmap(
data = X, values = "weighted_casualties", include = c("WI"), regions = "counties", color = "red"
)+
scale_fill_continuous(
low = "white", high = "red", name = "Red: More than Expected \n White: Fewer than Expected",
label = scales::comma
) +
labs(subtitle = "Weighted by County Population as Proportion of State Population\n (Normalized)") +
theme(legend.position = "right")
Mapper2 <-WZmap + theme(
plot.title = element_text(color = "red", size = 12, face = "bold"),
plot.subtitle = element_text(color = "blue"),
plot.caption = element_text(color = "black", face = "italic")
)
```
```{r}
# Density of population
fallen$Pop.Dense <- scale(fallen$Pop.Dense, center = TRUE, scale = TRUE)
X<-unique(fallen %>%
group_by(fips) %>%
mutate(number_casualties = n(),
weighted_casualties_density = number_casualties*(Pop.Dense)) %>%
select(fips,County, weighted_casualties_density))
WZmap<- usmap::plot_usmap(
data = X, values = "weighted_casualties_density", include = c("WI"), regions = "counties", color = "red"
)+
scale_fill_continuous(
low = "white", high = "red", name = "Red: More than Expected \n White: Fewer than Expected ",label = scales::comma
) +
labs(subtitle = "Weighted by County Population Density \n (Normalized)",
caption = "The Engagement Initiative creator: raymond.k.roberts@gmail.com.") +
theme(legend.position = "right")
Mapper3 <- WZmap + theme(
plot.subtitle = element_text(color = "blue"),
plot.caption = element_text(color = "black", face = "italic", hjust = -0.15)
)
```
# Collective Views
```{r}
ggarrange(Mapper1 , Mapper2, Mapper3 + rremove("x.text"),
ncol = 1, nrow = 3)
```