-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-intro.Rmd
60 lines (39 loc) · 2.64 KB
/
01-intro.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
# Working with Spatial Data in R {#intro}
## Forms of Spatial Data
Spatial data comes in two basic forms, raster (gridded) and vector (points, lines and polygons).
Raster data are often used to represent continuous variables, _e.g._ temperature, rainfall or elevation. Whereas vector data are used to represent sampling locations, weather station locations (and data at that point), roads, state or national outlines or other regions that may be natural or manufactured.
Understanding how these data differ is important to being able to use them in maps in R.
## Spatial Packages
Spatial data has its own unique properties. Packages that are commonly used with spatial data in R include
* [_raster_](https://CRAN.R-project.org/package=raster) [@raster],
* [_sf_](https://CRAN.R-project.org/package=sf) [@sf],
* [_rnaturalearth_](https://CRAN.R-project.org/package=rnaturalearth) [@rnaturalearth],
* [_rnaturalearthdata_](https://CRAN.R-project.org/package=rnaturalearthdata),
* [_ggspatial_](https://CRAN.R-project.org/package=ggspatial) [@ggspatial],
* _grid_ (this is a part of your base R installation) and
* [_gridExtra_](https://CRAN.R-project.org/package=gridExtra).
The _raster_ package is used to handle raster data files but also offers capabilities to download and import other data including country-level outlines ([GADM](https://gadm.org/)), elevation (SRTM data) and bioclimatic variables from [Worldclim](https://www.worldclim.org/).
_sf_ is used to handle vector-format files and _ggplot2_ now offers `geom_sf()` for easy plotting of _sf_ objects.
_rnaturalearth_ and _rnaturalearthdata_ facilitate mapping using data from [http://www.naturalearthdata.com/](http://www.naturalearthdata.com/).
_ggspatial_ is used to add map elements such as scale bars and north arrows to _ggplot2_ objects.
_grid_ and _gridExtra_ are used to add what are called "neatlines", an outline around the map to contain all the elements of the map.
You may also want to visit [https://rspatial.org](https://rspatial.org/) for more packages, tutorials and information.
## Exercises
### Install Spatial Packages
Install the packages necessary for working with spatial data in R. _This will take a few moments to complete._
```{r install-spatial, eval=FALSE}
install.packages(c(
"raster",
"sf",
"rnaturalearth",
"rnaturalearthdata",
"ggspatial"
))
```
Once the main packages are installed, the second step is to install the _rnaturalearthhires_ package as well.
Answer `1` to download and install the necessary data. Again, this will also take some time.
```{r install-spatial-2, eval=FALSE}
library(rnaturalearth)
install_rnaturalearthhires()
```
Now we are ready to make some maps!