This chapter explores mapping of point patterns:
Under the course folder, please create a folder called “lab9”. Next, in the lab9 folder, please create two sub-folders that one is called “data” and another one is “plot”.
This chapter uses:
Download the lab’s data:
If there you have any questions about the above-mentioned steps, please refer to Chapter 3.2.3 for detailed instructions.
Again, we would like to start a new project from scratch with a clean R Script. Please do the following steps. If you have any questions about these steps, please refer to the relevant chapters for help.
Please install necessary packages as needed.
library(dplyr) # mutate, left_join
library(sf)
library(geojsonio) ## import geojson
library(tmap) ## mapping
library(spatstat) ## kernel density map
Simple Features (sf) - spatial data
# colorado state: county subdivision (cartographic boundary)
sf_co_cousub <- st_read("data/cb_2023_us_cousub/cb_2023_us_cousub_500k.shp") %>%
filter(STATE_NAME == "Colorado")
## Reading layer `cb_2023_us_cousub_500k' from data source
## `D:\OneDrive\UCCS\Teaching\GES4070\Labs\01_git_wk\uccs_geoviz\data\cb_2023_us_cousub\cb_2023_us_cousub_500k.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 36367 features and 14 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -179.1467 ymin: -14.5487 xmax: 179.7785 ymax: 71.38782
## Geodetic CRS: NAD83
# crash data
sf_crash <- st_read("data/crash_data/cos_crash_2024.shp")
## Reading layer `cos_crash_2024' from data source
## `D:\OneDrive\UCCS\Teaching\GES4070\Labs\01_git_wk\uccs_geoviz\data\crash_data\cos_crash_2024.shp'
## using driver `ESRI Shapefile'
## replacing null geometries with empty geometries
## Simple feature collection with 6017 features and 29 fields (with 160 geometries empty)
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -105.3126 ymin: 38.74474 xmax: -104.6317 ymax: 39.03464
## Geodetic CRS: WGS 84
# road data
sf_road <- st_read("data/tl_2023_08041_roads/tl_2023_08041_roads.shp")
## Reading layer `tl_2023_08041_roads' from data source
## `D:\OneDrive\UCCS\Teaching\GES4070\Labs\01_git_wk\uccs_geoviz\data\tl_2023_08041_roads\tl_2023_08041_roads.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 29689 features and 4 fields
## Geometry type: LINESTRING
## Dimension: XY
## Bounding box: xmin: -105.0685 ymin: 38.51945 xmax: -104.0516 ymax: 39.13004
## Geodetic CRS: NAD83
Project to CRS NAD83 / Colorado North (ftUS). CRS code: 2231
# project to CRS NAD83 / Colorado North (ftUS)
sf_co_cousub <- st_transform(sf_co_cousub, 2231)
# el paso county: county subdivision
sf_ep_cousub <- sf_co_cousub %>% filter(NAMELSADCO == "El Paso County")
# olorado springs
sf_cos_cousub <- sf_ep_cousub %>% filter(NAME == "Colorado Springs")
Examine the crash data.
# top 5 rows
head(sf_crash, 5)
# data type
str(sf_crash)
Filter data
# extract records with non-empty geometry
sf_crash_24 <- sf_crash[!st_is_empty(sf_crash),]
# project to CRS NAD83 / Colorado North (ftUS)
sf_crash_24 <- st_transform(sf_crash_24, 2231)
Visualization: quick interactive map.
# set tmap mode for interactive mapping
tmap_mode("view")
# plot crash data and cos county subdivision
tm_shape(sf_cos_cousub) + tm_polygons(alpha = 0, lwd = 5, border.col = "blue") +
tm_shape(sf_crash_24) + tm_dots(alpha = 0.5)