::p_load(tidyverse, tmap, sf, sfdep) pacman
In Class Exercise 5
Getting Started
Importing Module
Importing Data
<- st_read(dsn = "data",
studyArea layer = "study_area") %>%
st_transform(crs = 3829)
Reading layer `study_area' from data source
`C:\Users\Daniel\Desktop\Github\IS419\IS415-GAA\In-Class_Ex\In-Class_Ex05\data'
using driver `ESRI Shapefile'
Simple feature collection with 7 features and 7 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 121.4836 ymin: 25.00776 xmax: 121.592 ymax: 25.09288
Geodetic CRS: TWD97
Note
CRS 3829 = Taiwan’s projection map
Can refer to EPSG.io
<- st_read(dsn = "data",
stores layer = "stores") %>%
st_transform(crs = 3829)
Reading layer `stores' from data source
`C:\Users\Daniel\Desktop\Github\IS419\IS415-GAA\In-Class_Ex\In-Class_Ex05\data'
using driver `ESRI Shapefile'
Simple feature collection with 1409 features and 4 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 121.4902 ymin: 25.01257 xmax: 121.5874 ymax: 25.08557
Geodetic CRS: TWD97
Visualizing the SF layer
Note
The sequence of the layout matters if overlapping
tmap_mode("view")
tm_shape(studyArea) +
tm_polygons() +
tm_shape(stores) +
tm_dots(col = "Name",
size = 0.01,
border.col = "black",
border.lwd = 0.5) +
tm_view(set.zoom.limits = c(12, 16))
Local Colocation Quotients (LCLQ)
Note
Taking only 6 neighbors. Include self will make it 7 so that there will never be a 50-50 change
= include_self(
nb st_knn(st_geometry(stores), 6))
Note
Converting into distance weight matrix
Nearer target, higher weight, lower = lesser
<- st_kernel_weights(nb,
wt
stores,"gaussian",
adaptive = TRUE)
Note
Making it a vector
<- stores %>%
FamilyMart filter(Name == "Family Mart")
<- FamilyMart$Name A
<- stores %>%
SevenEleven filter(Name == "7-Eleven")
<- SevenEleven$Name B
Note
A = Interest
B = neighbour to check colocation
nb = location (circle to search)
wt = weight
49 = simulation (will convert to P value after that)
NA = No results, not near each other
<- local_colocation (A, B, nb, wt, 49) LCLQ
Note
Remember not to sort. Sequence is important
<- cbind(stores, LCLQ) LCLQ_stores
tmap_mode("view")
tm_shape(studyArea) +
tm_polygons() +
tm_shape(LCLQ_stores) +
tm_dots(col = "X7.Eleven", size = 0.01) +
tm_view(set.zoom.limits = c(12,18))