-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 19.3 KB
/
.Rhistory
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
clean_inc =
income_pln %>%
select(level_1, level_3, value) %>%
rename(breakdown = level_1) %>%
rename(pln_area = level_3)
joined_income =
left_join(clean_inc, crosswalk, by = "pln_area") %>%
mutate(scaled = as.numeric(value * prop_of_pln))
test_income =
joined_income %>%
group_by(breakdown, eld_bounds) %>%
mutate(sum_eld = sum(scaled)) %>%
arrange(breakdown, eld_bounds)
test_income
test_income %>% filter(eld_bounds == "HOLLAND-BUKIT TIMAH", breakdown == "$2,000 - $2,999")
test_income %>%
filter(breakdown == "Total")
total_income =
test_income %>%
filter(breakdown == "Total") %>%
group_by(eld_bounds) %>%
summarise(pop_in_000 = mean(sum_eld)) ## Mean is the same as adding and then dividing!
total_income
## List of Levels
inc_levels <- list('Below $1,000',
'$1,000 - $1,999',
'$2,000 - $2,999',
'$3,000 - $3,999',
'$4,000 - $4,999',
'$5,000 - $5,999',
'$6,000 - $6,999',
'$7,000 - $7,999',
'$8,000 - $8,999',
'$9,000 - $9,999',
'$10,000 - $10,999',
'$11,000 - $11,999',
'$12,000 & Over'
)
#Calculate each level of income as a percentage of total population
income_value_pct <- function(level) {
test_income %>%
filter(breakdown == level) %>%
group_by(eld_bounds) %>%
summarise(pop_in_000 = mean(sum_eld)) %>%
mutate(pct = 100* (pop_in_000 / total_income$pop_in_000)) %>%
mutate(inc_level = level) # We include this so we know what we are looking at
}
eld_income <- lapply(inc_levels, income_value_pct) %>% bind_rows()
eld_income
#Make yuhua histogram
# selectedbounds =
# tibble(eld_income) %>% filter(eld_bounds == c("PIONEER", "ANG MO KIO"))
ggplot(eld_income, aes(fill=factor(inc_level, levels=rev(inc_levels)), y=pct, x=eld_bounds)) +
geom_bar(position="fill", stat="identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size=20),
axis.title.x = element_text(size=30),
axis.title.y = element_text(size = 30),
axis.text.y = element_text(size=20),
legend.box.background = element_rect(),
legend.box.margin = margin(6, 6, 6, 6),
legend.key.size = unit(2,'cm'),
legend.title = element_text(size=18, face='bold'),
legend.text = element_text(size=15)) + xlab("Electoral Boundary Name") +
ylab("Percentage of Population") + labs(fill = "Income Levels") + coord_flip()
edu_pln <- read.csv("data/raw/edu_pln.csv")
edu_pln
# Let's just keep the columns that we want and throw out the rest.
clean_edu =
edu_pln %>%
select(level_1, level_3, value) %>%
rename(breakdown = level_1) %>%
rename(pln_area = level_3)
joined_edu =
left_join(clean_edu, crosswalk, by = "pln_area") %>%
mutate(scaled = as.numeric(value * prop_of_pln))
test_edu =
joined_edu %>%
group_by(breakdown, eld_bounds) %>%
mutate(sum_eld = sum(scaled)) %>%
arrange(breakdown, eld_bounds)
test_edu
total_edu =
test_edu %>%
filter(breakdown == "Total") %>%
group_by(eld_bounds) %>%
summarise(pop_in_000 = mean(sum_eld)) ## Mean is the same as adding and then dividing!
total_edu
## List of Levels
edu_levels <- list('No Qualification',
'Primary',
'Lower Secondary',
'Secondary',
'Post-Secondary (Non-Tertiary)',
'Polytechnic',
'Professional Qualification and Other Diploma',
'University'
)
#Calculate each level of edu as a percentage of total population
edu_value_pct <- function(level) {
test_edu %>%
filter(breakdown == level) %>%
group_by(eld_bounds) %>%
summarise(pop_in_000 = mean(sum_eld)) %>%
mutate(pct = 100* (pop_in_000 / total_edu$pop_in_000)) %>%
mutate(edu_level = level) # We include this so we know what we are looking at
}
eld_edu <- lapply(edu_levels, edu_value_pct) %>% bind_rows()
eld_edu
#Make education barplot
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x=eld_bounds)) +
geom_bar(position="fill", stat="identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size=20),
axis.title.x = element_text(size=30),
axis.title.y = element_text(size = 30),
axis.text.y = element_text(size=20),
legend.box.background = element_rect(),
legend.box.margin = margin(6, 6, 6, 6),
legend.key.size = unit(2,'cm'),
legend.title = element_text(size=18, face='bold'),
legend.text = element_text(size=15)) + xlab("Electoral Boundary Name") +
ylab("Percentage of Population") + labs(fill = "Education Levels") + coord_flip()
voting <- read_csv("data/raw/voting.csv")
voted_pap = voting %>% filter(year==2020, party=="PAP") %>% mutate(vote_pap_pct = as.numeric(vote_percentage) * 100) %>% select(constituency, vote_pap_pct) # Data from the 2020 Elections
# We pivot the data to get the income and ed
pivoted_income = eld_income %>% select(-"pop_in_000") %>% pivot_wider(names_from = inc_level, values_from = pct)
pivoted_edu = eld_edu %>% select(-"pop_in_000") %>% pivot_wider(names_from = edu_level, values_from = pct)
eld_2 = eld %>% select(c("Name", "geometry")) # We make a copy of the Electoral Boundary file with the columns we want
join_income_eld = inner_join(eld_2, pivoted_income, by=c("Name"='eld_bounds')) # We join income data to eld data first
join_edu_data = inner_join(join_income_eld, pivoted_edu, by=c("Name"="eld_bounds")) # Join Edu Data with income Data
eld_data =
inner_join(join_edu_data, voted_pap, by=c("Name"="constituency")) %>%
mutate(across(where(is.numeric), round, 2)) #Round values
tibble(eld_data)
write.csv(eld_data, file="eld_data.csv")
write.csv(eld_income, file="eld_income.csv")
write_sf(eld_data, "eld_data.shp")
mypal <- c('#edf8fb', '#b3cde3', '#8c96c6','#8856a7','#810f7c')
tmap_mode("plot")
tm_shape(eld_data) + tm_polygons("vote_pap_pct", title = "Percentage Voted for PAP", palette = mypal) + tm_borders() + tm_text("Name", size = 1/3)
tmap_mode("view")
income_map =
tm_shape(eld_data) + tm_text("Name", size = 1/1.3) + tm_borders(lwd = 2) +
tm_polygons("vote_pap_pct", title = "Percentage Voted for PAP",
popup.vars=c(
"Income Below $1,000: " = "Below $1,000",
"Income $1,000 - $1,999: " = "$1,000 - $1,999",
"Income $2,000 - $2,999: " = "$2,000 - $2,999",
"Income $3,000 - $3,999: " = "$3,000 - $3,999",
"Income $4,000 - $4,999: " = "$4,000 - $4,999",
"Income $5,000 - $5,999: " = "$5,000 - $5,999",
"Income $6,000 - $6,999: " = "$6,000 - $6,999",
"Income $7,000 - $7,999: " = "$7,000 - $7,999",
"Income $8,000 - $8,999: " = "$8,000 - $8,999",
"Income $9,000 - $9,999: " = "$9,000 - $9,999",
"Income $10,000 - $10,999: " = "$10,000 - $10,999",
"Income $11,000 - $11,999: " = "$11,000 - $11,999",
"Income above $12,000: " = "$12,000 & Over",
"Percentage who voted for PAP: " = "vote_pap_pct")
) + tm_layout(title="Income (2015) and PAP Vote Share (2020)")
tmap_leaflet(income_map, show = TRUE, add.titles=TRUE)
edu_map =
tm_shape(eld_data) + tm_text("Name", size = 1/1.3) + tm_borders(lwd = 2) +
tm_polygons("vote_pap_pct", title = "Percentage Voted for PAP",
popup.vars=c(
"No Qualification: " = "No Qualification",
"Primary: " = "Primary",
"Lower Secondary: " ="Secondary",
"Secondary: " = "Secondary",
"Post-Secondary (Non-Tertiary): " = "Post-Secondary (Non-Tertiary)",
"Polytechnic: " = "Polytechnic",
"Professional Qualification and Other Diploma: " = "Professional Qualification and Other Diploma",
"University: " = "University",
"Percentage who voted for PAP: " = "vote_pap_pct")
) + tm_layout(title="Highest Edu Qualification (2015) and PAP Vote Share (2020)")
tmap_leaflet(edu_map, show = TRUE, add.titles=TRUE)
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/barchart/barchart.R')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/barchart/barchart.R')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/barchart/barchart.R')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/barchart/barchart.R')
ui <- fluidPage(
titlePanel("Neospec Visualization"),
sidebarLayout(
sidebarPanel(
uiOutput("FaceUnitOut"),
tags$hr(),
uiOutput("FaceTypeOut")
),
mainPanel(
tabsetPanel(
tabPanel("Table", dataTableOutput("table"),6),
h3("Data table view"),
#withSpinner(DT::dataTableOutput("contents"),6),
#dataTableOutput("tt"),
h3("Raw Neospec signatures"),
withSpinner(plotOutput("plts"),6)
)
)
)
)
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
shinyServer(function(input, output) {
output$distPlot <- renderPlot({
x_axis <- input$selectedCol
gg <-
ggplot(mtcars, aes_string(x = x_axis, y = "hp", color = "cyl"))
gg <- gg + geom_point()
gg
})
})
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
eld_data
eld_data$Name
bounds = eld_data$Name
bounds
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
ggplot(eld_income, aes_string(x = x_axis, y = "hp", color = "cyl"))
ggplot(eld_income, aes_string(x = "MARINE PARADE", y = "hp", color = "cyl"))
ggplot(eld_income, aes_string(x = MARINE PARADE, y = "hp", color = "cyl"))
ggplot(eld_income, aes_string(x = 'MARINE PARADE', y = "hp", color = "cyl"))
ggplot(eld_edu, aes_string(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x=eld_bounds))
ggplot(eld_income, aes_string(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x=eld_bounds))
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x=eld_bounds)) +
# ggplot(mtcars, aes_string(x = x_axis, y = "hp", color = "cyl"))
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x=eld_bounds))
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x=eld_bounds))
## List of Levels
edu_levels <- list('No Qualification',
'Primary',
'Lower Secondary',
'Secondary',
'Post-Secondary (Non-Tertiary)',
'Polytechnic',
'Professional Qualification and Other Diploma',
'University'
)
#Make education barplot
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x=eld_bounds)) +
geom_bar(position="fill", stat="identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size=20),
axis.title.x = element_text(size=30),
axis.title.y = element_text(size = 30),
axis.text.y = element_text(size=20),
legend.box.background = element_rect(),
legend.box.margin = margin(6, 6, 6, 6),
legend.key.size = unit(2,'cm'),
legend.title = element_text(size=18, face='bold'),
legend.text = element_text(size=15)) + xlab("Electoral Boundary Name") +
ylab("Percentage of Population") + labs(fill = "Education Levels") + coord_flip()
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x=eld_bounds)) +
geom_bar(position="fill", stat="identity")
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "JURONG")) +
geom_bar(position="fill", stat="identity")
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= c("JURONG", "ALJUNIED"))) +
geom_bar(position="fill", stat="identity")
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "JURONG")) +
geom_bar(position="fill", stat="identity")
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "JURONG")) +
geom_bar(position="fill", stat="identity") + facet_grid(.~eld_bounds)
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "JURONG")) +
geom_bar(position="fill", stat="identity") + facet_grid(."SEMBAWANG")
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "JURONG")) +
geom_bar(position="fill", stat="identity") + facet_grid(.~"SEMBAWANG")
test_edu =
eld_edu %>% filter("Name" == c("JURONG", "SEMBAWANG"))
test_edu =
eld_edu %>% filter("Name" = c("JURONG", "SEMBAWANG"))
test_edu =
eld_edu %>% filter("Name" == c("JURONG", "SEMBAWANG"))
test_edu =
eld_edu %>% filter("Name" == "JURONG")
test_edu
test_edu =
eld_edu %>% filter("eld_bounds" == "JURONG")
test_edu
eld_edu
test_edu =
eld_edu %>% filter("eld_bounds" == "HOUGANG")
test_edu
eld_edu
test_edu =
eld_edu %>% filter(eld_bounds == "HOUGANG")
test_edu
test_edu =
eld_edu %>% filter(eld_bounds == c("HOUGANG", "JURONG"))
test_edu
test_edu =
eld_edu %>% filter(eld_bounds %in% c("HOUGANG", "JURONG"))
test_edu
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "JURONG")) +
geom_bar(position="fill", stat="identity") + facet_grid(.~eld_bounds)
ggplot(eld_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "JURONG")) +
geom_bar(position="fill", stat="identity") #+ facet_grid(.~eld_bounds)
ggplot(test_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "JURONG")) +
geom_bar(position="fill", stat="identity") + facet_grid(.~eld_bounds)
ggplot(test_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "JURONG")) +
geom_bar(position="fill", stat="identity") + facet_grid(~eld_bounds.)
ggplot(test_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "JURONG")) +
geom_bar(position="fill", stat="identity") + facet_grid(.~eld_bounds)
ggplot(test_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "JURONG")) +
geom_bar(position="fill", stat="identity") + facet_grid(eld_bounds)
ggplot(test_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "JURONG")) +
geom_bar(position="fill", stat="identity") + facet_grid(~eld_bounds)
ggplot(test_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "test")) +
geom_bar(position="fill", stat="identity") + facet_grid(~eld_bounds)
ggplot(test_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "Boundary Name")) +
geom_bar(position="fill", stat="identity") + facet_grid(~eld_bounds)
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
runApp()
runApp()
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
runApp()
runApp()
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2')
runApp('test')
runApp('test')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test')
bounds
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test/barchart_working.R')
bounds
bounds?
/
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test/barchart_working.R')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test/barchart_working.R')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test/barchart_working.R')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test/barchart_working.R')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2/test/barchart_working.R')
runApp('Downloads/MapDemo')
runApp('Downloads/MapDemo')
runApp('Documents/UChicago/Academics/Spring 2021/GIS 3/MapDemo 2')
runApp('Downloads/MapDemo')
runApp('Downloads/MapDemo')
runApp('Downloads/MapDemo')
runApp('Downloads/MapDemo')
runApp('Downloads/MapDemo')
runApp('Downloads/MapDemo')
runApp('Downloads/MapDemo/shiny_gis3.R')
runApp('Downloads/MapDemo/shiny_gis3.R')
runApp('Downloads/MapDemo/shiny_gis3.R')
runApp('Downloads/MapDemo/shiny_gis3.R')
runApp('Downloads/MapDemo/shiny_gis3.R')
runApp('Downloads/MapDemo/shiny_gis3.R')
shinyAppDir(
system.file("shiny_gis3", package="shiny"),
options = list(width = "100%", height = 700)
)
shinyAppDir(
system.file("/shiny_gis3", package="shiny"),
options = list(width = "100%", height = 700)
)
shinyAppDir(
system.file("shiny_gis3", package="shiny"),
options = list(width = "100%", height = 700)
)
shinyAppDir(
system.file("shiny_gis3.R", package="shiny"),
options = list(width = "100%", height = 700)
)
shinyAppDir(
system.file("shiny_gis3", package="shiny"),
options = list(width = "100%", height = 700)
)
shinyAppDir(
system.file("/Users/joseaevan5/Documents/gis3/shiny_gis3", package="shiny"),
options = list(width = "100%", height = 700)
)
shinyApp(
ui = fluidPage(
# App title ----
titlePanel("Singapore Electoral Boundary Data Explorer"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
sidebarPanel(
h3("Make your choice"),
helpText("Explore Singapore data based on selected variables"),
selectInput(
"selectedCol1",
"Select 1st boundary to compare",
choices = list("ALJUNIED",
"ANG MO KIO",
"BISHAN-TOA PAYOH",
"BUKIT BATOK",
"BUKIT PANJANG",
"CHUA CHU KANG",
"EAST COAST",
"HOLLAND-BUKIT TIMAH",
"HONG KAH NORTH",
"HOUGANG",
"JALAN BESAR",
"JURONG",
"KEBUN BARU",
"MACPHERSON",
"MARINE PARADE",
"MARSILING-YEW TEE",
"MARYMOUNT",
"MOUNTBATTEN",
"NEE SOON",
"PASIR RIS-PUNGGOL",
"PIONEER",
"POTONG PASIR",
"PUNGGOL WEST",
"RADIN MAS",
"SEMBAWANG",
"SENGKANG",
"TAMPINES",
"TANJONG PAGAR",
"WEST COAST",
"YIO CHU KANG",
"YUHUA"),
selected = "Bound 1"
),
selectInput(
"selectedCol2",
"Select 2st boundary to compare",
choices = list("ALJUNIED",
"ANG MO KIO",
"BISHAN-TOA PAYOH",
"BUKIT BATOK",
"BUKIT PANJANG",
"CHUA CHU KANG",
"EAST COAST",
"HOLLAND-BUKIT TIMAH",
"HONG KAH NORTH",
"HOUGANG",
"JALAN BESAR",
"JURONG",
"KEBUN BARU",
"MACPHERSON",
"MARINE PARADE",
"MARSILING-YEW TEE",
"MARYMOUNT",
"MOUNTBATTEN",
"NEE SOON",
"PASIR RIS-PUNGGOL",
"PIONEER",
"POTONG PASIR",
"PUNGGOL WEST",
"RADIN MAS",
"SEMBAWANG",
"SENGKANG",
"TAMPINES",
"TANJONG PAGAR",
"WEST COAST",
"YIO CHU KANG",
"YUHUA"),
selected = "Bound 2"
),
selectInput("Map_Choice",
label = "View electoral boundary level data on an interactive map of Singapore",
choices = list("Income Data",
"Education Data"),
selected = "Income Data"),
h4("About"),
p("This project was completed by Josea Evan, as part of coursework for GIS III at the University of Chicago. Contact: josea [at] uchicago.edu"),
h4("Data Source"),
p("This data is from the Singapore Census. Electoral Data from 2020 Singapore General Election. Income and Education Data crosswalked from 2015 Household Survey.")
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Tabset w/ plot, summary, and table ----
tabsetPanel(type = "tabs",
tabPanel("Education Data", plotOutput("distPlot")),
tabPanel("Income Data", plotOutput("incPlot")),
tabPanel("Map", leafletOutput("working_map"))
)
)
)
),
server <- function(input, output) {
output$distPlot <- renderPlot({
test_edu =
eld_edu %>% filter(eld_bounds %in% c(input$selectedCol1, input$selectedCol2))
ggplot(test_edu, aes(fill=factor(edu_level, levels=rev(edu_levels)), y=pct, x= "Boundary Name")) +
geom_bar(position="fill", stat="identity") + facet_grid(~eld_bounds) +
theme(legend.box.background = element_rect(),
legend.title = element_text(face='bold')) +
labs(fill = "Highest Education Level Attained (2015)") +
ylab("Percentage of Population")
})
#Generate a Violin Plot of Variables
output$incPlot <- renderPlot({
test_inc =
eld_income %>% filter(eld_bounds %in% c(input$selectedCol1, input$selectedCol2))
ggplot(test_inc, aes(fill=factor(inc_level, levels=rev(inc_levels)), y=pct, x= "Boundary Name")) +
geom_bar(position="fill", stat="identity") + facet_grid(~eld_bounds) +
theme(legend.box.background = element_rect(),
legend.title = element_text(face='bold')) +
labs(fill = "Gross Monthly Income from Work (2015)") +
ylab("Percentage of Population")
})
output$working_map <- renderLeaflet({
map <- switch(input$Map_Choice,
"Income Data" = income_map,
"Education Data" = edu_map)
working_map <- tmap_leaflet(map)
})
},
options = list(height = 500)
)
library(shiny); runApp('Documents/gis3/shiny_gis3.R')