-
Notifications
You must be signed in to change notification settings - Fork 0
/
Map practice.Rmd
326 lines (244 loc) · 9.83 KB
/
Map practice.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
---
title: "practice"
author: "Grace Kim"
date: "11/28/2019"
output: html_document
---
This R markdown was used to practice the various ggplot mappings of the South Korean peninsula, and create the base images needed for the shiny app that moved through the various density maps of the different religous populations in Korea.
```{r setup, include=FALSE}
# need all of our libraries!
knitr::opts_chunk$set(echo = TRUE)
require(rgdal)
library(ggplot2)
library(dplyr)
library(broom)
library(readxl)
library(janitor)
library(cartogram)
library(scales)
```
```{r Data cleaning}
# read in the korea religions dataset :D
x <- read_xlsx("Korea/raw-data/2015_Religions_Korea.xlsx") %>%
clean_names()
# need to clean the data for only the numbers in each religous group
clean <- x %>%
filter(gender == "Total") %>%
tail(17) %>%
select(-matches("age")) %>%
select(-matches("gender"))
# change column name of region names to id for joining the various datasets later
colnames(clean)[1]<-"id"
#############################################################
############### START OF SHAPEFILE STUFF ####################
#############################################################
# Read in Shape files of the korean administrative area boundaries
shp <- readOGR("Korea/raw-data/KOR_adm/KOR_adm1.shp", stringsAsFactors = F)
# tidyed the data for the region :D, need the region name so that the longitude data points match up the various busan seoul other area names
shp_df<- tidy(shp, region = "NAME_1")
head(shp_df)
joined <- inner_join(shp_df,clean, by = "id")
joined
#shp@data <- inner_join(shp@data,clean, by = "NAME_1")
#shp@data
```
```{r Mapping}
# create all the various images for the shiny app
png("Korea/graphics/populationKorea.png")
png("Korea/graphics/allReligionsKorea.png")
png("Korea/graphics/buddhismKorea.png")
png("Korea/graphics/christProtesKorea.png")
png("Korea/graphics/christCathKorea.png")
png("Korea/graphics/wonBuddhismKorea.png")
png("Korea/graphics/confucianismKorea.png")
png("Korea/graphics/cheondoismKorea.png")
png("Korea/graphics/noReligionKorea.png")
# need a dataframe that has only the names of the various south korea administrative
# regions
cnames <- aggregate(cbind(long, lat) ~ id, data=joined,
FUN=function(x)mean((x)))
# geom polygon to plot the map in ggplot :D
# needed to group each administrative regions by group
# just made completely separate maps for every image
#### POPULATION DENSITY MAP ####
ggplot() +
# add the various geometric shapes for the different korean regions
geom_polygon(data = joined,
aes(x = long,
y = lat,
group = group,
fill = as.numeric(total)),
colour = "white",
size=0,
alpha=0.9) +
# gradient scale for purple to be higher dense regions, blue/white lower scale
scale_fill_gradient2(low = "white",
mid = scales::muted("light blue"),
high = "purple",
labels = comma) +
theme_void() +
labs(title = "South Korea population density based on geographic region",
fill = "Population")+
geom_label(data = cnames, aes(x=long, y=lat, label=id),size = 1.5)
# geom_text(data = cnames,aes(long, lat, label = id), size=2)
ggsave("Korea/graphics/populationKorea.png",width = 7, height = 7)
#### Religious Total ####
ggplot() +
# add the various geometric shapes for the different korean regions
geom_polygon(data = joined,
aes(x = long,
y = lat,
group = group,
fill = as.numeric(religious_total)),
colour = "white",
size=0,
alpha=0.9) +
# gradient scale for purple to be higher dense regions, blue/white lower scale
scale_fill_gradient2(low = "white",
mid = scales::muted("light blue"),
high = "purple",
labels = comma) +
theme_void() +
labs(title = "Population of religious individuals based on geographic region",
fill = "Population")
ggsave("Korea/graphics/allReligionsKorea.png",width = 7, height = 7)
#### Buddhism map ####
ggplot() +
# add the various geometric shapes for the different korean regions
geom_polygon(data = joined,
aes(x = long,
y = lat,
group = group,
fill = as.numeric(buddhism)),
colour = "white",
size=0,
alpha=0.9) +
# gradient scale for purple to be higher dense regions, blue/white lower scale
scale_fill_gradient2(low = "white",
mid = scales::muted("light blue"),
high = "purple",
labels = comma) +
theme_void() +
labs(title = "Population of Buddhists based on geographic region",
fill = "Population")
ggsave("Korea/graphics/buddhismKorea.png",width = 7, height = 7)
##### Christian Protestant map ####
ggplot() +
# add the various geometric shapes for the different korean regions
geom_polygon(data = joined,
aes(x = long,
y = lat,
group = group,
fill = as.numeric(christianity_protestant)),
colour = "white",
size=0,
alpha=0.9) +
# gradient scale for purple to be higher dense regions, blue/white lower scale
scale_fill_gradient2(low = "white",
mid = scales::muted("light blue"),
high = "purple",
labels = comma) +
theme_void() +
labs(title = "Population of Protestant Christians based on geographic region",
fill = "Population")
ggsave("Korea/graphics/christProtesKorea.png",width = 7, height = 7)
#### Christian Catholic map ####
ggplot() +
# add the various geometric shapes for the different korean regions
geom_polygon(data = joined,
aes(x = long,
y = lat,
group = group,
fill = as.numeric(christianity_catholic)),
colour = "white",
size=0,
alpha=0.9) +
# gradient scale for purple to be higher dense regions, blue/white lower scale
scale_fill_gradient2(low = "white",
mid = scales::muted("light blue"),
high = "purple",
labels = comma) +
theme_void() +
labs(title = "Population of Catholic Christians based on geographic region",
fill = "Population")
ggsave("Korea/graphics/christCathKorea.png",width = 7, height = 7)
#### Won Buddhism map ####
ggplot() +
# add the various geometric shapes for the different korean regions
geom_polygon(data = joined,
aes(x = long,
y = lat,
group = group,
fill = as.numeric(won_buddhism)),
colour = "white",
size=0,
alpha=0.9) +
# gradient scale for purple to be higher dense regions, blue/white lower scale
scale_fill_gradient2(low = "white",
mid = scales::muted("light blue"),
high = "purple",
labels = comma) +
theme_void() +
labs(title = "Population of Won Buddhists based on geographic region",
fill = "Population")
ggsave("Korea/graphics/wonBuddhismKorea.png",width = 7, height = 7)
#### Confucianism map ####
ggplot() +
# add the various geometric shapes for the different korean regions
geom_polygon(data = joined,
aes(x = long,
y = lat,
group = group,
fill = as.numeric(confucianism)),
colour = "white",
size=0,
alpha=0.9) +
# gradient scale for purple to be higher dense regions, blue/white lower scale
scale_fill_gradient2(low = "white",
mid = scales::muted("light blue"),
high = "purple",
labels = comma) +
theme_void() +
labs(title = "Population of Confucianists based on geographic region",
fill = "Population")
ggsave("Korea/graphics/confucianismKorea.png",width = 7, height = 7)
#### Confucianism map ####
ggplot() +
# add the various geometric shapes for the different korean regions
geom_polygon(data = joined,
aes(x = long,
y = lat,
group = group,
fill = as.numeric(cheondoism)),
colour = "white",
size=0,
alpha=0.9) +
scale_fill_gradient2(low = "white",
mid = scales::muted("light blue"),
high = "purple",
labels = comma) +
theme_void() +
labs(title = "Population of Cheondoists based on geographic region",
fill = "Population")
ggsave("Korea/graphics/cheondoismKorea.png",width = 7, height = 7)
#### no religion map ####
ggplot() +
# add the various geometric shapes for the different korean regions
geom_polygon(data = joined,
aes(x = long,
y = lat,
group = group,
fill = as.numeric(no_religion)),
colour = "white",
size=0,
alpha=0.9) +
# gradient scale for purple to be higher dense regions, blue/white lower scale
scale_fill_gradient2(low = "white",
mid = scales::muted("light blue"),
high = "purple",
labels = comma) +
theme_void() +
labs(title = "Population of non-religious individuals based on geographic region",
fill = "Population")
ggsave("Korea/graphics/noReligionKorea.png",width = 7, height = 7)
```