26 Aug 2024
This code chunk imports shapefile.
Reading layer `MP14_SUBZONE_WEB_PL' from data source
`C:\tskam\IS415-GAA\In-class_Ex\In-class_Ex02\data' using driver `ESRI Shapefile'
Simple feature collection with 323 features and 15 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 2667.538 ymin: 15748.72 xmax: 56396.44 ymax: 50256.33
Projected CRS: SVY21
This code chunk imports kml file.
Reading layer `MPSZ-2019' from data source
`C:\tskam\IS415-GAA\In-class_Ex\In-class_Ex02\data' using driver `ESRI Shapefile'
Simple feature collection with 332 features and 6 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 103.6057 ymin: 1.158699 xmax: 104.0885 ymax: 1.470775
Geodetic CRS: WGS 84
Reading layer `URA_MP19_SUBZONE_NO_SEA_PL' from data source
`C:\tskam\IS415-GAA\In-class_Ex\In-class_Ex02\data\MasterPlan2019SubzoneBoundaryNoSeaKML.kml'
using driver `KML'
Simple feature collection with 332 features and 2 fields
Geometry type: MULTIPOLYGON
Dimension: XY, XYZ
Bounding box: xmin: 103.6057 ymin: 1.158699 xmax: 104.0885 ymax: 1.470775
z_range: zmin: 0 zmax: 0
Geodetic CRS: WGS 84
Write a code chunk to check the project of the imported sf objects.
Coordinate Reference System:
User input: WGS 84
wkt:
GEOGCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["latitude",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["longitude",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4326]]
Re-write the code chunk to import the Master Plan Sub-zone 2019 and Pre-schools Location with proper transformation
Reading layer `MPSZ-2019' from data source
`C:\tskam\IS415-GAA\In-class_Ex\In-class_Ex02\data' using driver `ESRI Shapefile'
Simple feature collection with 332 features and 6 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 103.6057 ymin: 1.158699 xmax: 104.0885 ymax: 1.470775
Geodetic CRS: WGS 84
Reading layer `PRESCHOOLS_LOCATION' from data source
`C:\tskam\IS415-GAA\In-class_Ex\In-class_Ex02\data\PreSchoolsLocation.kml'
using driver `KML'
Simple feature collection with 2290 features and 2 fields
Geometry type: POINT
Dimension: XYZ
Bounding box: xmin: 103.6878 ymin: 1.247759 xmax: 103.9897 ymax: 1.462134
z_range: zmin: 0 zmax: 0
Geodetic CRS: WGS 84
Write a single line code to perform the following tasks:
Derive the area of each planning sub-zone.
Drop the unit of measurement of the area (i.e. m^2)
Calculate the density of pre-school at the planning sub-zone level.
Using appropriate Exploratory Data Analysis (EDA) and Confirmatory Data Analysis (CDA) methods to explore and confirm the statistical relationship between Pre-school Density and Pre-school count.
Tip: Refer to ggscatterstats()
of ggstatsplot package.
popdata2023 <- popdata %>%
group_by(PA, SZ, AG) %>%
summarise(`POP`=sum(`Pop`)) %>%
ungroup() %>%
pivot_wider(names_from=AG,
values_from = POP)
colnames(popdata2023)
[1] "PA" "SZ" "0_to_4" "10_to_14" "15_to_19"
[6] "20_to_24" "25_to_29" "30_to_34" "35_to_39" "40_to_44"
[11] "45_to_49" "50_to_54" "55_to_59" "5_to_9" "60_to_64"
[16] "65_to_69" "70_to_74" "75_to_79" "80_to_84" "85_to_89"
[21] "90_and_Over"
Write a code chunk to derive a tibble data.framewith the following fields PA, SZ, YOUNG, ECONOMY ACTIVE, AGED, TOTAL, DEPENDENCY where by:
popdata2023 <- popdata2023 %>%
mutate(YOUNG=rowSums(.[3:6]) # Aged 0 - 24, 10 - 24
+rowSums(.[14])) %>% # Aged 5 - 9
mutate(`ECONOMY ACTIVE` = rowSums(.[7:13])+ # Aged 25 - 59
rowSums(.[15])) %>% # Aged 60 -64
mutate(`AGED`=rowSums(.[16:21])) %>%
mutate(`TOTAL`=rowSums(.[3:21])) %>%
mutate(`DEPENDENCY`=(`YOUNG` + `AGED`)
/ `ECONOMY ACTIVE`) %>%
select(`PA`, `SZ`, `YOUNG`,
`ECONOMY ACTIVE`, `AGED`,
`TOTAL`, `DEPENDENCY`)
The code chunk below is used to change data in the PA and SZ fields into uppercase.
The code chunk below is used to perform left-join whereby the join fields are SUBZONE_N from the mpsz19_shp sf data.frame and SZ from the popdata2023 data.frame.
tm_shape(mpsz_pop2023)+
tm_fill("DEPENDENCY",
style = "quantile",
palette = "Blues",
title = "Dependency ratio") +
tm_layout(main.title = "Distribution of Dependency Ratio by planning subzone",
main.title.position = "center",
main.title.size = 1,
legend.title.size = 1,
legend.height = 0.45,
legend.width = 0.35,
bg.color = "#E4D5C9",
frame = F) +
tm_borders(alpha = 0.5) +
tm_compass(type="8star", size = 1.5) +
tm_scale_bar() +
tm_grid(alpha =0.2) +
tm_credits("Source: Planning Sub-zone boundary from Urban Redevelopment Authorithy (URA)\n and Population data from Department of Statistics (DOS)",
position = c("left", "bottom"))