Hot Spots
Animating by year with GIF in Markdown
To animate by year, try the code below.
Give the code chunk the eval=FALSE
option so that Rmarkdown does not try to run this while knitting.
anim_speed <- 3
anim_duration <- (max(all_country_data$Year) -
min(all_country_data$Year) + 1) /
anim_speed
animate(animation1,
fps = anim_speed,
duration = anim_duration)
anim_save(here("scripts", "life_gdp.gif")
Afterward, include the animation in your markdown using Markdown to include an image. Start with !
followed by []
with the alternate text and ()
with the file path. Note that the animation should be stored in the same folder as the Rmd file for this to work. If you move the resulting html, copy the animation file to the same location.

Loading and saving Census data
We don’t want to query the Census servers every time we run our code, so it’s best to download data as follows: Check to see if the data already exists. If not, download it and save it as an RDS file. Then, load the RDS file.
countiesRDS <- here("data_public", "counties_vermont.RDS")
if(!file.exists(countiesRDS)){
vermont_counties <- counties(state = "Vermont", cb=TRUE)
saveRDS(vermont_counties, countiesRDS)
}
vermont_counties <- readRDS(countiesRDS)
Notebook for lab
Tmap
Tmap is awesome for mapping because:
view
mode creates a dynamic Leaflet mapplot
mode that creates a static graph- Syntax has the feel of
ggplot
- Classifying data is easy
- You can add more than one data layer
- Incredibly customizable
Get started! with data on hurricane tracks from the International best track archive for climate stewardship
Rendered Animation
Spatial Correlation
Tobler’s first law of geography states that “everything is related to everything else, but near things are more related than distant things”.
This is spatial dependence, a.k.a. spatial autocorrelation, and it suggests that some degree of spatial clustering is to be expected. However, researchers are often interested in whether spatial clustering is unusually pronounced. Are there significant spatial hotspots of vehicle break-ins? Cases of leukemia? Earthquakes? High college exam scores? UFO sightings? Social media posts about a conspiracy theory?
Spatial statistics can help answer these questions, both globally (is clustering present in the region of study? yes or no?) and locally (is clustering present in a particular location? Where are significant clusters located?)
Getis Ord
One of the first tests students learn in statistics is the T-test to determine whether two samples have different means.
The Getis Ord statistic is a spatial version of the T-test, in which one sample is a local neighborhood and the other sample is everywhere else. The test is calculated for every location on the map, and reports whether the neighborhood around each location has significantly higher or lower values than everywhere else. In other words, it uses statistics to find hot spots.
Defining ``local’’
A Spatial Weights Matrix formally defines ``neighborhoods’’ for the purposes of spatial statistics. There are many ways to define a neighborhood, but the most common ways are to use a defined distance radius (e.g. every geographic unit within 20 miles) or topological adjacency (e.g. every geograhpic unit with a common boundary).
References
The following references on spatial statistics are not required reading: they are references for the theoretical/technical details of spatial cluster detection.
- Livings, M. and Wu, A-M. (2020). Local Measures of Spatial Association. The Geographic Information Science & Technology Body of Knowledge (3rd Quarter 2020 Edition), John P. Wilson (Ed.). DOI: 10.22224/gistbok/2020.3.10
- Ord, J. K., and A. Getis. 1995. Local Spatial Autocorrelation Statistics: Distributional Issues and an Application. Geographical Analysis 27 (4):286–306. DOI:10.1111/j.1538-4632.1995.tb00912.x download
- Rogerson, P. A. 2006. Statistical Methods for Geography: A Student’s Guide. SAGE Publications. (this has a new addition, 2020) handout
- Getis Ord spreadsheet
- spdep package localG man and localG page
- Michael Minn’s basic point pattern analysis in R
- Michael Kearney’s intro to rtweet