Skip to content

Teaching materials on advanced R programming for spatial data

Notifications You must be signed in to change notification settings

Robinlovelace/cs7

Repository files navigation

Welcome to cs7

This is the online, up-to-date home for the course Intermediate and Advanced R for Spatial Data Analysis.

It is also a metapackage in the sense that when you install it, many of the packages the tutorials depend on will be installed on your computer. Because this metapackage is not on CRAN, we use the devtools package to install it:

if(!require(devtools))
  install.packages("devtools")
devtools::install_github("robinlovelace/cs7")

Learning outcomes

By the end of the course participants will:

  • Be more efficient general R programmers
  • Understand standard (non-spatial) data structures and how to subset, process and analyse them
  • Understand the structure of spatial data in R
  • Be able to query, subset and analyse spatial objects
  • Have a working knowledge of fundamental GIS functions such as changing projections
  • Be proficient in the use of R to create maps using add-on packages such as tmap
  • Have some experience with advanced functionality such as raster data and interactive maps

Resources

The course website/wiki is github.com/robinlovelace/cs7

Course content

The course is structured in 45 minute classes which mix practical and lecture content, with an emphasis on one or the other in each class. The timings each day are as follows:

10:00 - 11:30 classes (2)

11:30 - 11:45 coffee break

11:45 - 13:15 classes (2)

13:15 - 14:00 lunch break

14:00 - 15:30 classes (2)

15:30 - 15:45 coffee break

15:45 - 18:45 classes (4)

Day 1: From introductory to intermediate R

  • Introduction: (10:00 - 11:30)
    • 30 minute lecture: why R for 'Geographic Data Science'?
    • 15 minute demonstration of effective use of R and RStudio
    • 45 minute practical: exploring your R/RStudio set-up
      • Boosting productivity with RStudio (ERP 2.5)
      • How R's ecosystem works: packages, tutorials, help forums and code sharing sites (ERP 4.4 and ERP 10)

11:30 - 11:45 coffee break

  • Objects, functions and concepts for efficient R programming (11:45 - 13:15)
    • R packages (15 minute talk, 30 minute group activity)
    • 15 minutes intro, 30 minutes hands on with the Vectors chapter of R for Data Science (Wickham and Grolemund 2016)

13:15 - 14:00 lunch break

  • Vectors and lists (Chapter 20 of R4DS) (14:00 - 14:45):
  • Data input/output (14:45 - 15:30)
    • Aim: get some 'raw' data ready for next class, e.g. on:
    • Weather conditions in countries worldwide
    • Economic performance of countries in Europe
    • Species distributions
    • Soil types
    • CO2 emissions
  • Data sources (15 minute lecture)
  • Practical (30 minutes): obtain data, from web, APIs packages
    • Quick go round: what is your dataset?
    • Optional extra (advanced): reproduce benchmarks in (ERP 5

15:30 - 16:00 coffee break

  • Tidying data (16:00 - 17:15)
    • Introduction to data cleaning (15 minute lecture)
    • Practical (45 minutes): work through http://r4ds.had.co.nz/tidy-data.html
    • Regular expressions (15 minute practical)
      • Work through the guidance in the regular expressions vignette provided by: vignette("regular-expressions")

17:15 - 17:20 minute break

Day 2: Basics of R as a GIS

  • An introduction to spatial data with sp (10:00 - 11:30)
  • An introduction to spatial classes (lecture 30 minutes)
  • Practical handout: creating-maps-in-R, Part I and II
  • Spatial data classes IVSDR II (30 minutes)
  • Subsetting data and basic plotting (30 minutes)

11:30 - 11:45 coffee break

  • Creating and manipulating spatial data IVSDR III (11:45 - 13:15)
  • Creating spatial data (30 minutes)
  • Projections (30 minutes)
    • Transforming data using spTransform()
  • Attribute joins (30 minutes)
  • Bonus topic: spatial subsetting and spatial joins

13:15 - 14:00 lunch break

  • Demonstration and discussion of the Propensity to Cycle Tool (PCT) (15 minute lecture)
  • Basic visualisation based on creating-maps-in-R (Part IV) (14:15 - 15:30)
  • Introduction to plotting paradigms in R (lecture)
    • Base graphics
    • ggplot2
    • tmap
  • Applying the methods to your own data

15:30 - 15:45 coffee break

  • Advanced visualisation (15:45 - 18:45) - options:
  • Completing Creating-maps-in-R tutorial: Visualising Spatial Data Tutorial (45 minutes)
  • Practical: Visualising Spatial Data Tutorial (45 minutes)
  • Visualising your own data to inform policy

Coffee break

  • Lecture and practical: interactive maps with R (45 minutes)
  • Advanced practical (challenge): Create an interactive map in shiny (30 minutes)

Day 3: Advanced Geographic Data with R

11:30 - 11:45 coffee break

  • Transport data with stplanr (12:30 - 13:15)
    • Exercise: Work through the package's vignette (vignette("introducing-stplanr")), which can also be found online.
    • Exercise (optional): Reproduce the analysis represented here on cycling potential over the Menai bridge with reference to the github.com/Robinlovelace/pct-menai repo and by installing the 'pctWales' package from GitHub:
devtools::install_github("robinlovelace/pct-menai")

Bonus test: can you reproduce these results?

13:15 - 14:00 lunch break

15:30 - 15:45 coffee break

library(raster)
poz = raster("data/poz_modified.tif")

17:15 - 17:20 Coffee break

  • Free session (17:20 onwards)
    • Identify the most interesting data and methods you have discovered during this course
    • Apply to the methods to generate new knowledge
    • Bonus: publis and communicate your work with GitHub/Rpubs.com

Prerequisites and course home

Working knowledge of R and RStudio is assumed.

Background reading (available online):

  • Torfs and Brauer (2014)
  • Colin Gillespie, Robin Lovelace (2016)
  • Lovelace and Cheshire (2014)

Background reading (not available online):

  • Bivand, Pebesma, and G’omez-Rubio (2013)
  • Dorman (2014)
  • Lamigueiro (2014)
  • Brunsdon and Comber (2015)

Further online materials

Contact: r.lovelace at leeds. ac. uk - for any questions or feedback on this course

References

Bivand, Roger S, Edzer J Pebesma, and Virgilio G’omez-Rubio. 2013. Applied Spatial Data Analysis with R. Vol. 747248717. Springer.

Brunsdon, Chris, and Lex Comber. 2015. An Introduction to R for Spatial Analysis & Mapping. Sage.

Colin Gillespie, Robin Lovelace. 2016. Efficient R Programming. http://shop.oreilly.com/product/0636920047995.do.

Dorman, Michael. 2014. Learning R for Geospatial Analysis. Packt Publishing Ltd.

Lamigueiro, Oscar Perpinan. 2014. Displaying Time Series, Spatial, and Space-Time Data with R. CRC Press.

Lovelace, Robin, and James Cheshire. 2014. “Introduction to Visualising Spatial Data in R.” Comprehensive R Archive Network, no. 03. https://github.com/Robinlovelace/Creating-maps-in-R.

Torfs, Paul, and Claudia Brauer. 2014. “A (Very) Short Introduction to R.” Comprehensive R Archive Network. http://cran.r-project.org/doc/contrib/Torfs+Brauer-Short-R-Intro.pdf.

About

Teaching materials on advanced R programming for spatial data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages