::p_load(sfdep, sf, tidyverse, tmap) pacman
In class exercise 5
Install and Load Packages
New package used is sfdep, used mainly for Local Co-Location Quotient
Importing Data
The national projection system of Taiwan is EPSG::3829
<- st_read(dsn = "data/",
studyArea layer = "study_area") %>%
st_transform(crs = 3829)
Reading layer `study_area' from data source
`/Users/junhaoteo/Documents/junhao2309/IS415/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
<- st_read(dsn = "data/",
stores layer = "stores") %>%
st_transform(crs = 3829)
Reading layer `stores' from data source
`/Users/junhaoteo/Documents/junhao2309/IS415/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
Visualising sf layers
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))
tmap_mode("plot")
local_colocation(A, B, nb, wt, nsim), where - A
Local Colocation Quotients (LCLQ)
<- include_self(
nb st_knn(st_geometry(stores), 6))
# The number 6 indicates getting the 6 nearest stores (nearest neighbor)
# List of lengths in nb showcases the numbers of the neighbors of a particular point
<- st_kernel_weights(nb,
wt
stores,"gaussian",
adaptive = TRUE)
# List of lengths in wt showcases the weights:
# The closer, the higher the weight, the further, the lower the weight
<- stores %>%
FamilyMart filter(Name == "Family Mart")
<- FamilyMart$Name
A
<- stores %>%
SevenEleven filter(Name == "7-Eleven")
<- SevenEleven$Name
B
<- local_colocation(A, B, nb, wt, 49)
LCLQ
<- cbind(stores, LCLQ) %>%
LCLQ_stores na.exclude()
# Place stores first as the function takes on the structure of the first input.
tmap_mode("view")
tm_shape(studyArea) +
tm_polygons() +
tm_shape(LCLQ_stores) +
tm_dots(col = "X7.Eleven",
size = 0.01,
border.col = "black",
border.lwd = 0.5) +
tm_shape(LCLQ_stores) +
tm_dots(col = "p_sim_7.Eleven",
size = 0.01,
border.col = "black",
border.lwd = 0.5)
tm_view(set.zoom.limits = c(12,16))
$tm_layout
$tm_layout$set.zoom.limits
[1] 12 16
$tm_layout$style
[1] NA
attr(,"class")
[1] "tm"