Show the code
::p_load(sf, sfdep, tmap, plotly, tidyverse) pacman
February 13, 2023
November 27, 2023
Emerging Hot Spot Analysis (EHSA) is a spatio-temporal analysis method for revealing and describing how hot spot and cold spot areas evolve over time. The analysis consist of four main steps:
As usual, p_load()
of pacman package will be used to check if the necessary packages have been installed in R, if yes, load the packages on R environment.
Five R packages are need for this in-class exercise, they are: sf, sfdep, tmap, plotly and tidyverse.
Using the steps you learned in previous lesson, install and load sf, tmap, sfdep and tidyverse packages into R environment.
For the purpose of this in-class exercise, the Hunan data sets will be used. There are two data sets in this use case, they are:
Before getting started, reveal the content of Hunan_GDPPC.csv by using Notepad and MS Excel.
In the code chunk below, st_read()
of sf package is used to import Hunan shapefile into R.
Reading layer `Hunan' from data source
`D:\tskam\ISSS624\In-class_Ex\In-class_Ex2\data\geospatial'
using driver `ESRI Shapefile'
Simple feature collection with 88 features and 7 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 108.7831 ymin: 24.6342 xmax: 114.2544 ymax: 30.12812
Geodetic CRS: WGS 84
Using the steps you learned in previous lesson, examine the content hunan sf data.frame
In the code chunk below, read_csv()
of readr is used to import Hunan_GDPPC.csv into R.
Using the steps you learned in previous lesson, examine the content the GDPPC tibble data.frame.
Before getting started, students must read this article to learn the basic concept of spatio-temporal cube and its implementation in sfdep package.
In the code chunk below, spacetime()
of sfdep is used to create an spacetime cube.
Next, is_spacetime_cube()
of sfdep package will be used to varify if GDPPC_st is indeed an space-time cube object.
The TRUE return confirms that GDPPC_st object is indeed an time-space cube.
Next, we will compute the local Gi* statistics.
The code chunk below will be used to identify neighbors and to derive an inverse distance weights.
activate()
of dplyr package is used to activate the geometry contextmutate()
of dplyr package is used to create two new columns nb and wt.set_nbs()
and set_wts()
set_nbs()
or set_wts()
.Note that this dataset now has neighbors and weights for each time-slice.
# A tibble: 6 × 5
Year County GDPPC nb wt
<dbl> <chr> <dbl> <list> <list>
1 2005 Anxiang 8184 <int [6]> <dbl [6]>
2 2005 Hanshou 6560 <int [6]> <dbl [6]>
3 2005 Jinshi 9956 <int [5]> <dbl [5]>
4 2005 Li 8394 <int [5]> <dbl [5]>
5 2005 Linli 8850 <int [5]> <dbl [5]>
6 2005 Shimen 9244 <int [6]> <dbl [6]>
We can use these new columns to manually calculate the local Gi* for each location. We can do this by grouping by Year and using local_gstar_perm()
of sfdep package. After which, we use unnest()
to unnest gi_star column of the newly created gi_starts data.frame.
With these Gi* measures we can then evaluate each location for a trend using the Mann-Kendall test. The code chunk below uses Changsha county.
Next, we plot the result by using ggplot2 functions.
We can also create an interactive plot by using ggplotly()
of plotly package.
In the above result, sl is the p-value. This result tells us that there is a slight upward but insignificant trend.
We can replicate this for each location by using group_by()
of dplyr package.
Lastly, we will perform EHSA analysis by using emerging_hotspot_analysis()
of sfdep package. It takes a spacetime object x (i.e. GDPPC_st), and the quoted name of the variable of interest (i.e. GDPPC) for .var argument. The k argument is used to specify the number of time lags which is set to 1 by default. Lastly, nsim map numbers of simulation to be performed.
In the code chunk below, ggplot2 functions ised used to reveal the distribution of EHSA classes as a bar chart.
Figure above shows that sporadic cold spots class has the high numbers of county.
In this section, you will learn how to visualise the geographic distribution EHSA classes. However, before we can do so, we need to join both hunan and ehsa together by using the code chunk below.
Next, tmap functions will be used to plot a categorical choropleth map by using the code chunk below.