-
Notifications
You must be signed in to change notification settings - Fork 11
/
README.Rmd
255 lines (173 loc) · 10.5 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
---
output: github_document
bibliography: creating-maps.bib
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
## 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:
```{r, eval=FALSE}
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](https://github.com/robinlovelace/cs7)
- Course overview: in https://github.com/robinlovelace/cs7
- Slides: Available from [slides](https://github.com/robinlovelace/cs7/tree/master/slides) folder
- Printed material:
- Introduction to Visualising Spatial Data with R
- Visualising spatial data: from Base to Shiny
- Point Pattern Analysis tutorial
- Online material: see https://github.com/robinlovelace/cs7 in the courses folder
- **stplanr**: A package for Transport Planning (stplanr-paper for short, available from [github.com/ropensci/stplanr](https://github.com/ropensci/stplanr/blob/master/vignettes/stplanr-paper.Rmd)), a detailed account of how to use spatial data in R as part of a transport planning workflow.
- Efficient R Programming (ERP): https://csgillespie.github.io/efficientR/
- R for Data Science (R4DS): http://r4ds.had.co.nz/
## 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](https://csgillespie.github.io/efficientR/set-up.html#rstudio))
- How R's ecosystem works: packages, tutorials, help forums and code sharing sites ([ERP 4.4](https://csgillespie.github.io/efficientR/workflow.html#package-selection) and [ERP 10](https://csgillespie.github.io/efficientR/learning.html))
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](http://r4ds.had.co.nz/vectors.html) of [R for Data Science](http://r4ds.had.co.nz) (Wickham and Grolemund 2016)
13:15 - 14:00 lunch break
- Vectors and lists ([Chapter 20 of R4DS](http://r4ds.had.co.nz/vectors.html)) (14:00 - 14:45):
- see http://r4ds.had.co.nz/vectors.html
- Types of vector data
- Dimensionality: lists, matrices, data frames and arrays
- 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](https://csgillespie.github.io/efficientR/input-output.html)
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
- Data carpentry with **dplyr** (17:20 - 18:45) [ERP 6.4](https://csgillespie.github.io/efficientR/data-carpentry.html)): https://csgillespie.github.io/efficientR/data-carpentry.html#dplyr
- Subsetting rows and columns ([6.4.3](https://csgillespie.github.io/efficientR/data-carpentry.html#filtering-rows))
- Creating new variables ([see 6.4.4](https://csgillespie.github.io/efficientR/data-carpentry.html#chaining-operations))
- Grouping and aggregating ([6.5.5](https://csgillespie.github.io/efficientR/data-carpentry.html#data-aggregation))
- Joining tables together ([6.5](https://csgillespie.github.io/efficientR/data-carpentry.html#combining-datasets))
## 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](https://github.com/Robinlovelace/Creating-maps-in-R), Part I and II
- Spatial data classes [IVSDR II](https://github.com/Robinlovelace/Creating-maps-in-R/blob/master/intro-spatial.Rmd#part-ii-spatial-data-in-r) (30 minutes)
- Subsetting data and basic plotting (30 minutes)
11:30 - 11:45 coffee break
- Creating and manipulating spatial data [IVSDR III](https://github.com/Robinlovelace/Creating-maps-in-R/blob/master/intro-spatial.Rmd#part-iii-creating-and-manipulating-spatial-data) (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](https://github.com/Robinlovelace/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
- Simple Features with R (10:00 - 11:30)
- Course handout: [Simple Features for Geographic Information](https://github.com/Robinlovelace/geocompr/releases/download/0.1/_main.pdf)
11:30 - 11:45 coffee break
- A short tutorial on GitHub (11:45 - 12:30)
- See: https://guides.github.com/activities/hello-world/
- An introduction to transport data with R (12:30 - 13:15)
<!-- - Spatio-temporal data with **spacetime** (11:30 - 13:45) -->
- Transport data with **stplanr** (12:30 - 13:15)
- Exercise: Work through the package's vignette (`vignette("introducing-stplanr")`), which can also be found [online](https://cran.r-project.org/web/packages/stplanr/vignettes/introducing-stplanr.html).
- Exercise (optional): Reproduce the analysis represented here on cycling potential over the Menai bridge with reference to the
[github.com/Robinlovelace/pct-menai](https://github.com/Robinlovelace/pct-menai/blob/master/vignettes/menai-bridge-cycle.Rmd) repo and by installing the 'pctWales' package from GitHub:
```{r, eval=FALSE}
devtools::install_github("robinlovelace/pct-menai")
```
**Bonus test**: can you reproduce [these results](http://rpubs.com/RobinLovelace/189307)?
13:15 - 14:00 lunch break
- Points pattern analysis - (14:00 - 15:30)
- Handout: [Point Pattern analysis](https://github.com/Robinlovelace/geocompr/blob/master/work-in-progress/10-point-pattern.Rmd)
15:30 - 15:45 coffee break
- Raster data with R (15:45 - 17:15)
- Run through this raster data tutorial: http://rspatial.org/spatial/rst/8-rastermanip.html
- See [historic raster data for Poznan](https://github.com/Robinlovelace/Creating-maps-in-R/blob/master/data/poz_modified.tif), which you can load with:
- Try to overlay vector data on top - apply methods from the tutorial to this poznan raster data
```{r, eval=FALSE}
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_very_2014
- @colin_gillespie_robin_lovelace_efficient_2016
- @lovelace_introduction_2014
Background reading (not available online):
- @bivand_applied_2013
- @dorman_learning_2014
- @lamigueiro_displaying_2014
- @brunsdon_introduction_2015
## Further online materials
- A free book on Geostatistics by Jakub Nowosad: https://github.com/Nowosad/geostatbook
- A document exploring cycling potential over the Menai Strait, UK: https://github.com/Robinlovelace/pct-menai/blob/master/vignettes/menai-bridge-cycle.Rmd
- A [tutorial on OSM data](https://github.com/Robinlovelace/osm-tutorial/blob/master/osm.pdf) with R (this is a little out of date). A more up-to-date resource is the [osmplotr](https://github.com/ropenscilabs/osmplotr) package - see there and other activity online to find out more.
Contact: r.lovelace at leeds. ac. uk - for any questions or feedback on this course
## References
```{r, echo=FALSE, eval=FALSE}
library(RefManageR)
bib = ReadZotero(user = 216746, .params = list(collection = 'VZ45CJWD', key = Sys.getenv("ZOTERO"), limit = 20))
WriteBib(bib = bib, file = "creating-maps.bib")
```