Spatial R workshop

A 2.5 day workshop conducted by Zev Ross to give you the skills needed to conduct spatial analysis in R.


R has an incredible number of spatial packages to enable a wide range of spatial tasks. End-to-end spatial analysis can now be done within R including creating and editing spatial data, geoprocessing, spatial statistics and the creation of elegant and interactive maps. But conducting spatial analysis in R is challenging for a variety of reasons including dealing with projections, making sense of spatial classes in R and knowing which of the many spatial packages can be used to perform the analyses you need. This workshop provides detailed coverage of the spatial-related topics you’ll need to conduct spatial analysis entirely within R.

Material Covered

  • Initial coverage of packages dplyr and ggplot2 (not specifically spatial, but useful in the course of the workshop)
  • Getting spatial data (packages covered include maps, tigris, choroplethr, osmar, UScensus 2010, acs)
  • Import/Export of spatial data (focus on rgdal and raster)
  • Anatomy of spatial files and classes (focus on classes in sp and raster including SpatialPoints, SpatialPolygons, RasterLayer, RasterBrick)
  • Coordinate reference systems (like it or not, it’s critically important to understand CRS when working with spatial data in R)
  • Working with spatial objects (basic object information, extracting slot information, using rgeos functions to extract geographic detail, appending, merging)
  • Static mapping (sp, ggplot2, ggmap, tmap)
  • Interactive mapping (leaflet)
  • Calculating distance (rgeos, geosphere)
  • Geoprocessing (buffer, intersect, etc, packages rgeos, raster)
  • Point pattern statistics (spatstat package, compare points to spatially random, computing density, quadrat counts)
  • Interpolation and geostatistics (inverse distance weighting, kernel density and, my favorite, kriging)

Topic examples

Use the ggplot2 package and faceting to create map panels:

ggplot(shp_df, aes(long, lat))+
   geom_polygon(aes(group=group, fill=BoroName),
                show_guide = FALSE)+
   facet_wrap(~BoroName, scale = "free")+
   theme(axis.text = element_blank(),axis.ticks = element_blank())


Analyze and plot raster data with the raster package:



Create interactive maps using the leaflet package:

# Mount Everest
leaflet() %>%  addProviderTiles("OpenTopoMap") %>% setView( 86.92, 27.99, zoom=8)

Conduct spatial analysis (in this case variography and kriging) with gstat:

v <- variogram(annualavg_pm25~1, air, cutoff=50000, cressie=TRUE) <- fit.variogram(v, vgm(2, "Sph", 20000, 1))
kr <- krige(annualavg_pm25~1, air, pred_locs,


The Instructor

Zev Ross is president of ZevRoss Spatial Analysis, a company focused on data science, statistics and data visualization. He has used R on a daily basis for nearly 15 years conducting data analysis and statistics for a wide range of clients including some of the world's largest public health agencies and Fortune 500 companies. Zev has authored or co-authored 30 scientific research papers and maintains a popular data science blog where he regularly posts on R-related topics. He is also an RStudio-recommended R programming consultant and trainer.

He has taught R workshops at major universities, at the American Cancer Society and in several different countries.

Workshop Format

The workshop involves a mix of slides, collaborative hands-on material and exercises and can be held at your university or institution. The workshop uses RStudio (An Technology of the Year, 2015). Participants use their own laptops (or computer facility) and will be provided with setup instructions. To fit with busy schedules the workshop can be held on weekdays or weekends. The workshop is designed for up to 10 participants (but let Zev know if you have a small or large group). For further details please don't hesitate to contact Zev directly.

This workshop is designed for intermediate to advanced R users and is not appropriate for beginners. This is also a relatively new workshop to meet the needs of an increasing number of R users who conduct spatial analysis in R. Anonymous feedback from participants in this workshop is below and for more feedback on Zev's workshops in general you can visit the Introduction to R workshop page.

Anonymous Feedback from Workshop Participants

"This workshop was incredibly informative", December 2015 (corporate client; Madison, WI)

"Very well done and clearly demonstrated", December 2015 (corporate client; Madison, WI)

"I enjoyed the course material and delivery", December 2015 (corporate client; Madison, WI)