This one day course will get you up-to-speed with using R and RStudio for daily working with spatial data. You will learn about R's powerful geospatial data processing, analysis and visualisation capabilities. It is practical and hands-on: you'll learn by doing. It assumes you already use R and want to extend your knowledge for spatial data applications. It will cover the recently developed sf package, which is compatible with the tidyverse, representing the cutting-edge of spatial data applications. It will provide a solid foundation (including spatial aggregation, joining, CRSs, visualisation) on which advanced analysis analysis workflows can be built.
install.packages("tidyverse")By the end of the course participants will:
In preparation for the course you should:
This should work:
library(sf)library(raster)library(spData)
install.packages("sf")
install.packages("spData")The course will be based on Chapter 4 of Geocomputation with R of the forthcoming book Geocomputation with R plus some additional materials:
Refreshments & set-up: (09:00 - 09:30)
Coffee break: (10:45 - 11:00)
LUNCH and looking at your data (12:30 - 13:30)
Worked example: car fleet analysis with Craig Morton (13:30 - 14:15)
Spatial data operations (14:15 - 15:00)
Coffee break: 15:00 - 15:15
Spatial operations on raster data (15:30 - 15:45)
Consolidating knowledge (15:45 - 16:15)
Wrap-up and next steps (16:15 - 16:30)
The popularity of spatial packages in R. The y-axis shows the average number of downloads, within a 30-day rolling window, of R's top 5 spatial packages, defined as those with the highest number of downloads last month.
library(spData) # see data(package = "spData") and ?afcon for more info
plot(afcon$x, afcon$y)

library(sp)data(meuse)coords = SpatialPoints(meuse[c("x", "y")])meuse = SpatialPointsDataFrame(coords, meuse)str(meuse)
## Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots## ..@ data :'data.frame': 155 obs. of 14 variables:## .. ..$ x : num [1:155] 181072 181025 181165 181298 181307 ...## .. ..$ y : num [1:155] 333611 333558 333537 333484 333330 ...## .. ..$ cadmium: num [1:155] 11.7 8.6 6.5 2.6 2.8 3 3.2 2.8 2.4 1.6 ...## .. ..$ copper : num [1:155] 85 81 68 81 48 61 31 29 37 24 ...## .. ..$ lead : num [1:155] 299 277 199 116 117 137 132 150 133 80 ...## .. ..$ zinc : num [1:155] 1022 1141 640 257 269 ...## .. ..$ elev : num [1:155] 7.91 6.98 7.8 7.66 7.48 ...## .. ..$ dist : num [1:155] 0.00136 0.01222 0.10303 0.19009 0.27709 ...## .. ..$ om : num [1:155] 13.6 14 13 8 8.7 7.8 9.2 9.5 10.6 6.3 ...## .. ..$ ffreq : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...## .. ..$ soil : Factor w/ 3 levels "1","2","3": 1 1 1 2 2 2 2 1 1 2 ...## .. ..$ lime : Factor w/ 2 levels "0","1": 2 2 2 1 1 1 1 1 1 1 ...## .. ..$ landuse: Factor w/ 15 levels "Aa","Ab","Ag",..: 4 4 4 11 4 11 4 2 2 15 ...## .. ..$ dist.m : num [1:155] 50 30 150 270 380 470 240 120 240 420 ...## ..@ coords.nrs : num(0) ## ..@ coords : num [1:155, 1:2] 181072 181025 181165 181298 181307 ...## .. ..- attr(*, "dimnames")=List of 2## .. .. ..$ : chr [1:155] "1" "2" "3" "4" ...## .. .. ..$ : chr [1:2] "x" "y"## ..@ bbox : num [1:2, 1:2] 178605 329714 181390 333611## .. ..- attr(*, "dimnames")=List of 2## .. .. ..$ : chr [1:2] "x" "y"## .. .. ..$ : chr [1:2] "min" "max"## ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot## .. .. ..@ projargs: chr NA12 year-old code still works (Pebesma and Bivand 2005)
plot(meuse, pch=1, cex = .05*sqrt(meuse$zinc))

sp has many reverse dependencies:
sp_revdeps = devtools::revdep("sp", dependencies = "Depends")head(sp_revdeps)
## [1] "adehabitat" "adehabitatHR" "adehabitatHS" "adehabitatLT"## [5] "adehabitatMA" "automap"length(sp_revdeps)
## [1] 135sp_revimps = devtools::revdep("sp", dependencies = "Imports")length(sp_revimps)
## [1] 256Online (dur) but with guidance, e.g. from:
A few of note:

library(sf)
## Linking to GEOS 3.5.1, GDAL 2.2.1, proj.4 4.9.2, lwgeom 2.3.3 r15473world_tbl = dplyr::as_data_frame(world)world_tbl
## # A tibble: 177 x 11## iso_a2 name_long continent## <chr> <chr> <chr>## 1 AF Afghanistan Asia## 2 AO Angola Africa## 3 AL Albania Europe## 4 AE United Arab Emirates Asia## 5 AR Argentina South America## 6 AM Armenia Asia## 7 AQ Antarctica Antarctica## 8 TF French Southern and Antarctic Lands Seven seas (open ocean)## 9 AU Australia Oceania## 10 AT Austria Europe## # ... with 167 more rows, and 8 more variables: region_un <chr>,## # subregion <chr>, type <chr>, area_km2 <dbl>, pop <dbl>, lifeExp <dbl>,## # gdpPercap <dbl>, geom <simple_feature>library(raster)r = raster(nrows = 3, ncols = 3)values(r) = 1:9plot(r)

Grolemund, G., Wickham, H., 2016. R for Data Science, 1 edition. ed. O’Reilly Media.
Lovelace, R., Nowosad, J., Meunchow, J., 2018. Geocomputation with R. CRC Press.
Pebesma, E.J., Bivand, R.S., 2005. Classes and methods for spatial data in R. R news 5, 9–13.
Links and example code from the course in Leeds: https://github.com/Robinlovelace/Creating-maps-in-R/blob/master/courses/leeds-2017-10.Rmd
Plug: GIS for Transport Applications: https://www.eventbrite.co.uk/e/gis-for-transport-applications-tickets-38491819067
This one day course will get you up-to-speed with using R and RStudio for daily working with spatial data. You will learn about R's powerful geospatial data processing, analysis and visualisation capabilities. It is practical and hands-on: you'll learn by doing. It assumes you already use R and want to extend your knowledge for spatial data applications. It will cover the recently developed sf package, which is compatible with the tidyverse, representing the cutting-edge of spatial data applications. It will provide a solid foundation (including spatial aggregation, joining, CRSs, visualisation) on which advanced analysis analysis workflows can be built.
install.packages("tidyverse")Keyboard shortcuts
| ↑, ←, Pg Up, k | Go to previous slide |
| ↓, →, Pg Dn, Space, j | Go to next slide |
| Home | Go to first slide |
| End | Go to last slide |
| Number + Return | Go to specific slide |
| b / m / f | Toggle blackout / mirrored / fullscreen mode |
| c | Clone slideshow |
| p | Toggle presenter mode |
| t | Restart the presentation timer |
| ?, h | Toggle this help |
| Esc | Back to slideshow |