-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path05-r-markdown-viz.Rmd
127 lines (89 loc) · 4.03 KB
/
05-r-markdown-viz.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
# (PART\*) Visualization {-}
# R Markdown and Custom Maps
## Learning Objectives
- Create a R Markdown document
- Embed code and text in an R Markdown document
- Manipulate R Markdown chunk options
- Become familiar with the `tmap` package
## Topics Learned
- .rmd structure
- Code chunks in R Markdown
```{block type="rmdwarning"}
Note: If you do not have LaTeX installed on your computer, please install `tinytex` using the following commands so that you will be able to Knit to a PDF and Beamer during this workshop.
> `install.packages('tinytex')`
> `tinytex::install_tinytex()`
```
```{block type="rmdinfo"}
Hint: Use the R Markdown guides in RStudio under Help > Cheatsheets > R Markdown Cheatsheet (or R Markdown Reference Guide) for help.
```
## Interactive Tutorial
```{block type="rmdinfo"}
This workshop's R Markdown can be found [here](https://github.com/spatialanalysis/workshop-scripts/blob/master/gis-visualization/winter-2019/doc/05-rmarkdown.Rmd).
```
## Challenges
We're going to continue using the data we used last week from the Chicago Data Portal, but we'll be working in a R Markdown document instead of a R script.
```{block type="learncheck"}
**Challenge**
```
1. Create a new R Markdown document. Knit the document.
2. Change the YAML header at the top to include your personal information. Try changing some of the options in the header (aka the options between the "---"):
- `output: pdf_document`
- `fontsize: 14pt`
You can use this [reference guide](https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf) to help you out.
```{block type="learncheck"}
```
```{block type="learncheck"}
**Challenge**
```
3. Use Markdown formatting to write some information about the Chicago libraries and community areas datasets. Use:
- sections
- bold/italic text
- two types of lists
```{block type="learncheck"}
```
```{block type="learncheck"}
**Challenge**
```
4. Insert an `ggplot2` image that we created last time in the document.
```{block type="learncheck"}
```
Here's the data from last week:
- [Libraries](https://data.cityofchicago.org/Education/Libraries-Locations-Hours-and-Contact-Information/x8fc-8rcq) points
- [Community Area](https://data.cityofchicago.org/Facilities-Geographic-Boundaries/Boundaries-Community-Areas-current-/cauq-8yn6) polygons
Remember: you can click on the "API" button to directly access the data, rather than having to download a csv via "Export".
```{block type="learncheck"}
**Challenge**
```
5. Add code chunks that:
- load packages
- read data
- create a ggplot2 plot
```{block type="learncheck"}
```
```{block type="learncheck"}
**Challenge**
```
6. Add chunk options that:
- load packages (hide this code)
- read data (show this code, and run it)
- create a ggplot2 plot (don't show this code, but run it, and control the size of the figure)
7. Try naming your chunks something useful.
```{block type="learncheck"}
```
```{block type="learncheck"}
**Challenge**
```
8. Try making a map with `tmap` (similar syntax as `ggplot2`), using the [`tmap` vignette](https://cran.r-project.org/web/packages/tmap/vignettes/tmap-getstarted.html).
```{block type="learncheck"}
```
```{block type="rmdinfo"}
Luc Anselin has written a more in-depth tutorial for tmap, which you can find and go through [here](https://spatialanalysis.github.io/tutorials/), under Introduction to Spatial Data Science > Basic Mapping.
```
## Links
All the links in this workshop:
- Link to Chicago Libraries data: https://data.cityofchicago.org/Parks-Recreation/Waterways/eg9f-z3t6
- Link to Chicago Community Areas data: https://data.cityofchicago.org/Facilities-Geographic-Boundaries/Boundaries-Community-Areas-current-/cauq-8yn6
- Link to R Markdown site: https://rmarkdown.rstudio.com
- Link to Software Carpentry R Markdown tutorial: https://swcarpentry.github.io/r-novice-gapminder/15-knitr-markdown/
- Getting started with `tmap` vignette: https://cran.r-project.org/web/packages/tmap/vignettes/tmap-getstarted.html
- Geocomputation with R - good chapter on making maps with `tmap`: https://geocompr.robinlovelace.net/adv-map.html