::p_load(tmap, sf, tidyverse) pacman
1: Urban Mobility Analysis
Urban Mobility analysis by using passenger volume by origin-destination bus stops.
Getting started
The code chunk below uses p_load() of pacman package to check if the required packages have been installed on the computer. If they are, the packages will be launched. The packages used are:
- tmap: for thematic mapping
- sf: for geospatial data wrangling
- tidyverse: for non-spatial data wrangling
The data sets used are:
- Master Plan 2019 Subzone Boundary (No Sea) (last updated Dec 2019) from data.gov.sg - reformatted into shapefile format
- Bus Stop Location (Last updated Jul 2023) from LTADataMall retrieved on 18 Nov 2023
- Passenger Volume by Origin Destination Bus Stops for Aug-Oct 2023 from LTADataMall retrieved on 18 Nov 2023
Import Passenger Volume by Origin-Destination Bus Stops
The code chunk below uses the read_csv()
function of readr package to import the csv file into R and save it as a R dataframe called odbus
.
<- read_csv("data/aspatial/origin_destination_bus_202308.csv") odbus
ORIGIN_PT_CODE
and DESTINATION_PT_CODE
are numeric variables that are categorical in nature. As such, they should be transformed to factor so that R treats them as a grouping variable.
$ORIGIN_PT_CODE <- as.factor(odbus$ORIGIN_PT_CODE)
odbus$DESTINATION_PT_CODE <- as.factor(odbus$DESTINATION_PT_CODE) odbus
Extract Commuting Flow data
The code chunk below extracts commuting flows on weekday during the rush hour (7am, 8am, 9am).
<- odbus %>%
origtrip_7_9 filter(DAY_TYPE == "WEEKDAY") %>%
filter(TIME_PER_HOUR >= 7 & TIME_PER_HOUR <= 9) %>%
group_by(ORIGIN_PT_CODE) %>%
summarise(TRIPS = sum(TOTAL_TRIPS))
Import Geospatial Data
Two geospatial data are used in this exercise.
Import Bus Stop Locations
The code chunk below uses the st_read()
function of sf package to import BusStop
shapefile into R as a simple feature data frame called BusStop
. As BusStop
uses svy21 projected coordinate system, the crs
is set to 3414.
<- st_read(dsn = "data/geospatial",
BusStop layer = "BusStop") %>%
st_transform(crs=3414)
Reading layer `BusStop' from data source
`C:\magdalenecjw\ISSS624 Geospatial\In_Class_Exercise\Ex1\data\geospatial'
using driver `ESRI Shapefile'
Simple feature collection with 5161 features and 3 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 3970.122 ymin: 26482.1 xmax: 48284.56 ymax: 52983.82
Projected CRS: SVY21
Import Planning Subzone data
The code chunk below uses the st_read()
function of sf package to import MPSZ-2019
shapefile into R as a simple feature data frame called mpsz
. To ensure we can use mpsz
together with BusStop
, mpsz
is reprojected to the svy21 projected coordinate system (crs=3413
).
<- st_read(dsn = "data/geospatial",
mpsz layer = "MPSZ-2019") %>%
st_transform(crs=3414)
Reading layer `MPSZ-2019' from data source
`C:\magdalenecjw\ISSS624 Geospatial\In_Class_Exercise\Ex1\data\geospatial'
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