For planning area, there are 55 areas but yet not all are residential areas with a handful with 0 population. For age cohort, there are 19 bands to visualize. The challenge is to visualize all the planning areas with the age bands at a glance. Solution: To exclude some of the planning areas that do not have population so as to declutter the visual.
To compare across the planning areas on the age band distribution will require putting the charts closer to each other for comparison with similar axis scales Solution: To explore ggridges or bar chart facet_wrap or heatmap for better comparison at a glance. Upon further research, ggridges seems to be for distribution over time rather than discrete distribution for age bands.
With 19 age bands, it will be challenging to differentiate the young and old especially comparing across the 55 planning areas. Solution: To explore using colour coding to differentiate the young, working adults and aged.
knitr::include_graphics("image/Bar chart.jpeg")
knitr::include_graphics("image/Heatmap.jpeg")
packages = c('tidyverse', 'forcats')
for (p in packages){
if(!require(p, character.only=T)){
install.packages(p)
}
library(p,character.only=T)
}
## Loading required package: tidyverse
## ── Attaching packages ───────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.0 ✓ purrr 0.3.3
## ✓ tibble 2.1.3 ✓ dplyr 0.8.4
## ✓ tidyr 1.0.2 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.4.0
## ── Conflicts ──────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
# read data file
poppyramid <- read.csv("data/respopagesextod2011to2019.csv")
# filter for data in 2019
Pop2019 <- filter(poppyramid, Time=="2019")
# exclude Pop values = 0
Pop2019nozero <- filter(Pop2019, Pop != 0)
# create new column for economic age group
Pop2019nozero ["Economic Age Group"] <-NA
# group the age bands into economic age group
for(i in 1:nrow(Pop2019nozero))
Pop2019nozero$`Economic Age Group`[i] <- if (Pop2019nozero$AG[i] == "0_to_4" | Pop2019nozero$AG[i] == "05_to_9" | Pop2019nozero$AG[i] == "10_to_14" | Pop2019nozero$AG[i] == "15_to_19" | Pop2019nozero$AG[i] == "20_to_24") {
"Young"
} else {
if (Pop2019nozero$AG[i] == "25_to_29" | Pop2019nozero$AG[i] == "30_to_34" | Pop2019nozero$AG[i] == "35_to_39" | Pop2019nozero$AG[i] == "40_to_44" | Pop2019nozero$AG[i] == "45_to_49" | Pop2019nozero$AG[i] == "50_to_54" | Pop2019nozero$AG[i] == "55_to_59" | Pop2019nozero$AG[i] == "60_to_64") {
"Economically Active"
} else {
"Aged"
}
}
# plot bar chart
ggplot(data = Pop2019nozero, aes(x = AG, y = Pop, fill = `Economic Age Group`)) +
geom_bar(stat = "identity") +
scale_fill_manual(values=c("dark grey", "dark blue", "light blue"))+
scale_y_discrete(name="Population") +
scale_x_discrete(name="Age group") +
theme(axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.text.x = element_text(size = 7)) +
facet_wrap(~PA, labeller = label_wrap_gen(width = 14))
The bar chart shows the distribution of age bands across planning areas in 2019. The mature estates such as Bedok, Ang Mo Kio, Bukit Merah shows a higher distribution of “Aged” compared to “Young”. In contrast, new estates like SengKang and Punggol shows a high distribution of younger age bands within the “Young” group and a high distribution of working adults age bands within the “Economically Active” group. Semi-mature estates such as Pasir Ris and Serangoon show a similar pattern of the “Young” group growing up and their parents age band in the “Economically Active” group moving towards the “Aged” group. The chart also shows the population density of each planning area - it is clear that the heartlands are the highly residential areas while the city areas like Orchard, Downtown Core are less populated.
Pop_data <- Pop2019nozero %>%
group_by(PA, AG) %>%
summarise (Total_Pop = sum(Pop))
ggplot(Pop_data, aes(x=AG, y=fct_rev(PA), fill = Total_Pop)) +
geom_tile() +
scale_x_discrete(name="Age") +
scale_y_discrete(name = "Planning area") +
scale_fill_distiller(palette = "Blues", direction = 1) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))