-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.Rmd
450 lines (382 loc) · 15.8 KB
/
index.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
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
---
title: "Singapore Data Project"
date: "Created: 26 May, 2022.\nUpdated: `r format(Sys.time(), '%d %B, %Y')`"
output:
html_document:
code_folding: hide
theme: cosmo
highlight: tango
fig_width: 8
fig_height: 5
toc: yes
toc_depth: 2
toc_float: yes
number_sections: false
---
```{r Setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(scales)
library(glue)
library(paletteer)
```
# Exploring Publicly Available Data in Singapore
Data.gov.sg was launched in 2011 as a one-stop portal to its publicly-available data sets from 70 public agencies. It recently underwent a revamp, and has a new-look website. Other than data from [data.gov.sg](https://data.gov.sg), I also use data from the [Department of Statistics Singapore.](https://www.singstat.gov.sg) This is a personal project to practice R programming, and in the process hope to learn some insights from the data sets.
![](https://cdn.pixabay.com/photo/2017/03/16/05/23/singapore-2148190_960_720.jpg)
# Demographics
## Live Births and Fertility
Singapore has one of the lowest fertility rates globally [World Bank](https://data.worldbank.org/indicator/SP.DYN.TFRT.IN?locations=SG).
```{r Live births}
# Load data
live_births <- read_csv("data/births-and-fertility-annual/live-births.csv")
# Convert value to numeric
live_births$value <- as.numeric(as.character(live_births$value))
# Calculate long term mean
live_births %>%
group_by(level_1) %>%
summarize(across(value,
mean,
na.rm = TRUE)) %>%
ungroup()
# Plot number of live-births
live_births %>%
drop_na() %>%
ggplot(aes(x = year,
y = value,
colour = level_1)) +
geom_line(linewidth = 1.05) +
geom_hline(yintercept = 45000,
linetype = 2,
linewidth = 0.5) +
facet_wrap(~level_1,
scales = "free_x") +
scale_y_continuous(labels = label_number(big.mark = ",")) +
theme_classic() +
theme(legend.position = "none") +
scale_colour_paletteer_d("ggsci::default_jco") +
labs(x = "",
y = "",
title = "Number of Live-births in Singapore",
subtitle = "Dashed line at 45,000 represents the long term mean",
caption = "*Note: Resident Live-Births refers to births with at least one parent who is a Singapore citizen or permanent resident\nData: Department of Statistics (data.gov.sg) | Graphic: @weiyuet")
```
## Total Fertility Rate by Ethnic Groups
The Total Fertility Rate refers to the average number of live-births each female would have during her reproductive years if she were to experience the age-specific fertility rates prevailing during the period. It is derived by aggregating the age-specific fertility rates of females in each of the reproductive ages for a specific year.
```{r Fertility rate ethnic group}
# Load data
total_fertility_rate_by_ethnic_group <- read_csv("data/births-and-fertility-annual/total-fertility-rate-by-ethnic-group.csv")
# Plot fertility rate by ethnic groups
total_fertility_rate_by_ethnic_group %>%
ggplot(aes(x = year,
y = value,
colour = level_2)) +
geom_line() +
geom_point(aes(shape = level_2)) +
geom_hline(yintercept = 2.1,
linetype = 2,
linewidth = 0.5) +
theme_classic() +
theme(legend.title = element_blank(),
legend.position = c(0.85, 0.55)) +
scale_x_continuous(expand = c(0.01, 0),
limits = c(1960, 2020),
breaks = seq(1960, 2020, 5)) +
scale_y_continuous(breaks = seq(0, 8, 0.5),
labels = label_number(decimal.mark = '.',
accuracy = 0.1)) +
scale_colour_paletteer_d("ggsci::default_jco") +
labs(x = "",
y = "",
title = "Total Fertility Rate by Ethnic Groups",
subtitle = "Dashed line at 2.1 represents the population replacement rate",
caption = "Data: Department of Statistics (data.gov.sg) | Graphic: @weiyuet")
```
# Health
## Life Expectancy
In contrast to falling birth rates and fertility rates, the life expectancy has been increasing steadily.
```{r Life expectancy}
# Load data
life_expectancy <- read_csv('data/life-expectancy-by-sex-annual/life-expectancy-at-birth-and-age-65-years.csv')
# Plot data
# Line plot of life expectancy
life_expectancy %>%
ggplot(aes(x = year,
y = value,
colour = level_1)) +
geom_line(linewidth = 1) +
facet_wrap(vars(level_1),
scales = "free_y") +
scale_x_continuous(breaks = seq(1960, 2020, 10)) +
scale_colour_paletteer_d("ggsci::default_jco") +
labs(x = "",
y = "",
title = "Life Expectancy of Residents in Singapore",
caption = "Data: Ministry of Trade and Industry - Department of Statistics (data.gov.sg) | Graphic: @weiyuet") +
theme_classic() +
theme(legend.title = element_blank(),
legend.position = "none")
```
# Number of Students in Primary and Secondary Schools
Together with the falling birth rate, the number of students in primary and secondary schools have also been declining.
This has lead to the Ministry of Education [merging and closing schools.](https://www.moe.gov.sg/news/press-releases/20210407-school-mergers) Although, the student-teacher ratio has been decreasing (which is considered a positive metric).
## Number of Students in Primary Schools
```{r Number of students in primary schools}
# Load data
students_and_teachers_primary_schools <- read_csv("data/students-and-teachers-in-schools/students-and-teachers-primary-schools.csv")
# Plot number of students in primary schools
students_and_teachers_primary_schools %>%
ggplot(aes(x = year,
y = students_pri,
colour = school_type)) +
geom_line(linewidth = 1) +
facet_wrap(vars(sex)) +
guides(colour = guide_legend(nrow = 1)) +
scale_colour_paletteer_d("ggsci::default_jco") +
scale_x_continuous(breaks = seq(1980, 2020, 5)) +
scale_y_continuous(labels = label_number(big.mark = ","),
limits = c(10000, 250000)) +
labs(x = "",
y = "",
title = "Number of Students in Primary Schools",
colour = "School Type",
caption = "Data: Ministry of Education (data.gov.sg) | Graphic: @weiyuet") +
theme_classic() +
theme(legend.position = "bottom",
legend.title = element_blank())
```
## Student-Teacher Ratio in Primary Schools
```{r Student-teacher ratio in primary schools}
# Wrangle data
# Calculate student-teacher ratio
students_and_teachers_primary_schools <- students_and_teachers_primary_schools %>%
mutate(student_teacher_ratio = students_pri/teachers_pri)
students_and_teachers_primary_schools %>%
filter(sex == "MF") %>%
ggplot(aes(x = year,
y = student_teacher_ratio,
colour = school_type)) +
geom_smooth() +
geom_jitter() +
facet_wrap(vars(school_type)) +
scale_colour_paletteer_d("ggsci::default_jco") +
labs(x = "",
y = "",
title = "Student-Teacher Ratio in Primary Schools",
caption = "Data: Ministry of Education (data.gov.sg) | Graphic: @weiyuet") +
theme_classic() +
theme(legend.position = "none")
```
## Number of Students in Secondary Schools
```{r Number of students in secondary schools}
# Load data
students_and_teachers_secondary_schools <- read_csv("data/students-and-teachers-in-schools/students-and-teachers-secondary-schools.csv")
# Fix duplicate school types "Specialised Independant" and "Specialised Independent" and "Auto"
students_and_teachers_secondary_schools <- students_and_teachers_secondary_schools %>%
mutate(school_type = case_when(school_type == "Specialised Independant" ~ "Specialised Independent",
school_type == "Auto" ~ "Autonomous",
TRUE ~ school_type))
# Plot number of secondary school students
students_and_teachers_secondary_schools %>%
ggplot(aes(x = year,
y = student_sec,
colour = school_type)) +
geom_line(linewidth = 1) +
facet_wrap(vars(sex)) +
guides(colour = guide_legend(nrow = 1)) +
scale_colour_paletteer_d("ggsci::default_jco") +
scale_x_continuous(breaks = seq(1980, 2020, 5)) +
scale_y_continuous(breaks = seq(0, 200000, 25000),
labels = label_number(big.mark = ",")) +
labs(x = "",
y = "",
title = "Number of Students in Secondary Schools",
colour = "School Type",
caption = "Data: Ministry of Education (data.gov.sg) | Graphic: @weiyuet") +
theme_classic() +
theme(legend.position = "bottom",
legend.title = element_blank())
```
## Student-Teacher Ratio in Seondary Schools
```{r Student-teacher ratio in secondary schools}
# Wrangle data
# Calculate student-teacher ratio
students_and_teachers_secondary_schools <- students_and_teachers_secondary_schools %>%
mutate(student_teacher_ratio = student_sec/teacher_sec)
students_and_teachers_secondary_schools %>%
filter(sex == "MF") %>%
ggplot(aes(x = year,
y = student_teacher_ratio,
colour = school_type)) +
geom_smooth() +
geom_jitter() +
facet_wrap(vars(school_type),
scales = "free") +
scale_colour_paletteer_d("ggsci::default_jco") +
labs(x = "",
y = "",
title = "Student-Teacher Ratio in Secondary Schools",
caption = "Data: Ministry of Education (data.gov.sg) | Graphic: @weiyuet") +
theme_classic() +
theme(legend.position = "none")
```
# Infrastructure
## Housing
- Being an island state, land is limited, and thus housing is a perennial issue.
- The majority of people live in public housing, and the term evokes a different image compared to other countries.
## Flats Constructed By Housing And Development Board, Annual
```{r Flats constructed by hdb}
# Load data
flats_constructed <- read_csv("data/flats-constructed/flats-constructed-by-housing-and-development-board-annual.csv")
# Plot number of flats constructed
p <- flats_constructed %>%
ggplot(aes(x = year,
y = flats_constructed)) +
geom_step() +
scale_x_continuous(expand = c(0.01, 0),
limits = c(1975, 2020),
breaks = seq(1975, 2020, 5)) +
scale_y_continuous(limits = c(2000, 75000),
breaks = seq(5000, 75000, 10000),
labels = label_number(big.mark = ",")) +
labs(x = "",
y = "",
title = glue("Number of Flats Constructed by the Housing and Development Board ({min(flats_constructed$year)}-{max(flats_constructed$year)})"),
caption = "Data: Housing and Development Board (data.gov.sg) | Graphic: @weiyuet") +
theme_classic()
# Annotate
p + (annotate("text",
x = 1984,
y = 70000,
label = "67,017",
size = 3)) +
(annotate("text",
x = 2006,
y = 8000,
label = "2,733",
size = 3))
```
# Economy
## Container Throughput Monthly
```{r Container throughput monthly}
# Load data
container_throughput_monthly <- read_csv("data/container-throughput-monthly-total/container-throughput-monthly.csv")
# Separate month and year
container_throughput_monthly <- container_throughput_monthly %>%
separate(month,
c("year", "month"))
# Convert year and month into numeric
container_throughput_monthly <- container_throughput_monthly %>%
mutate(across(1:2,
as.numeric))
# Plot container throughput monthly
container_throughput_monthly %>%
ggplot(aes(x = month,
y = container_throughput)) +
geom_step() +
facet_wrap(vars(year)) +
scale_x_continuous(breaks = seq(1:12),
labels = month.abb[seq(1:12)]) +
scale_y_continuous(expand = c(0.1, 0)) +
labs(x = "",
y = "",
title = glue("Container Throughput ({min(container_throughput_monthly$year)}-{max(container_throughput_monthly$year)})"),
subtitle = "'000 Twenty-foot equivalent units",
caption = "Data: Maritime and Port Authority of Singapore (data.gov.sg) | Graphic: @weiyuet") +
theme_classic() +
theme(axis.text.x = element_text(angle = 90,
vjust = 0.5,
hjust = 1))
```
# Climate
## Number of Rain Days Monthly
```{r Number of rain days monthly}
# Load data
number_of_rain_days_monthly <- read_csv("data/rainfall-monthly-number-of-rain-days/rainfall-monthly-number-of-rain-days.csv")
# Separate year and month
number_of_rain_days_monthly <- number_of_rain_days_monthly %>%
separate(month, c("year", "month"))
# Convert year and month into numeric
number_of_rain_days_monthly <- number_of_rain_days_monthly %>%
mutate(year = as.numeric(year),
month = as.numeric(month))
# Plot number of rain days monthly
number_of_rain_days_monthly %>%
ggplot(aes(x = month,
y = no_of_rainy_days)) +
geom_point() +
geom_line() +
geom_hline(yintercept = 15,
linetype = "dotted",
colour = "red") +
facet_wrap(vars(year)) +
scale_x_continuous(breaks = 1:12,
labels = month.abb[1:12]) +
scale_y_continuous(breaks = seq(0, 30, 5)) +
labs(x = "",
y = "",
title = glue("Number of Rain Days per Month in Singapore ({min(number_of_rain_days_monthly$year)}-{max(number_of_rain_days_monthly$year)})"),
subtitle = "Recorded at Changi Climate Station (1.3667, 103.9833)",
caption = "Data: National Environment Agency (data.gov.sg) | Graphic: @weiyuet") +
theme_classic() +
theme(axis.text.x = element_text(angle = 90,
vjust = 0.5,
hjust = 1,
size = 7))
```
# Endemic Diseases
## Dengue Fever
```{r Weekly case numbers of dengue fever}
# Load data
weekly_infectious_disease <- read_csv('data/weekly-infectious-disease-bulletin-cases/weekly-infectious-disease-bulletin-cases.csv')
# Create new empty columns
col <- paste("col", 1:2)
# Split year and week column
weekly_infectious_disease <- weekly_infectious_disease %>%
separate(col = epi_week,
sep = "-",
into = col,
remove = TRUE)
weekly_infectious_disease <- weekly_infectious_disease %>%
rename(year = "col 1",
week = "col 2",
cases = "no._of_cases")
# Extract numbers from week column
weekly_infectious_disease$week <- as.numeric(str_extract(weekly_infectious_disease$week,
"[0-9]+"))
# Convert year into numeric
weekly_infectious_disease <- weekly_infectious_disease %>%
mutate(year = as.numeric(year))
# Clean disease names
weekly_infectious_disease <- weekly_infectious_disease %>%
mutate(disease = case_when(disease == "HFMD" ~ "Hand, Foot Mouth Disease",
disease == "Zika Virus Infection" ~ "Zika",
TRUE ~ disease))
# Plot weekly case numbers of Dengue Fever
disease_selected <- c("Dengue Fever")
# Calculate mean from sample period
weekly_infectious_disease %>%
filter(disease %in% disease_selected) %>%
group_by(disease) %>%
summarize(across(cases,
mean,
na.rm = TRUE)) %>%
ungroup()
weekly_infectious_disease %>%
filter(disease %in% disease_selected) %>%
ggplot(aes(x = week,
y = cases)) +
geom_col() +
facet_wrap(vars(year)) +
geom_hline(yintercept = 286,
linetype = "dashed",
colour = "red") +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
labs(x = "Week#",
y = "",
title = glue("Weekly Case Numbers of Dengue Fever in Singapore ({min(weekly_infectious_disease$year)}-{max(weekly_infectious_disease$year)})"),
subtitle = "Horizontal dashed line represents the mean of the entire data sample (mean = 286)",
caption = "Data: Ministry of Health (data.gov.sg) | Graphic: @weiyuet") +
theme_classic() +
theme(axis.ticks.x = element_blank())
```