forked from mdsumner/polar-mapping-oghub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_somap-polar-exploring.Rmd
114 lines (73 loc) · 3.37 KB
/
04_somap-polar-exploring.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
# SOmap
The `SOmap` package is intended to solve some of these problems, and provide an easier way to produce nice-looking maps of Antarctica and the Southern Ocean. It is primarily focused on maps in polar stereographic projection (although the `SOmap_auto` function extends this to other projections). `SOmap` won't necessarily get you exactly the map you want. But if it doesn't, it should hopefully get you close enough that you can make modifications to suit your exact purposes.
Please bear in mind that `SOmap` is still in development, and so its functionality (function parameters and/or behaviour) may change.
## Installation
Running code in this section is not required, we will discuss the use of SOmap.
To run the code in this session, you can run the following to install SOmap.
```{r SOmap-install,eval=FALSE}
remotes::install_github("AustralianAntarcticDivision/SOmap@dev-0.5")
```
By default, `SOmap` works with base graphics (and associated functionality from packages such as `raster` and `sp`). It is also possible to work with `ggplot2`-based graphics, as described below.
Start by loading the `SOmap` package and define some colours:
```{r somap_init, cache = FALSE, eval=TRUE}
library(SOmap)
```
```{r colors-dontuse, eval=FALSE, include=FALSE}
## also define a colour map to use for some examples
my_cmap <- colorRampPalette(c("#4D4140", "#596F7E", "#168B98",
"#ED5B67", "#E27766", "#DAAD50", "#EAC3A6"))(51)
```
```{r somap_pkgs, include = FALSE}
library(sp)
library(raster)
library(ggplot2)
```
## Circumpolar maps
A basic circumpolar map in polar stereographic projection:
```{r somap1, eval=TRUE}
SOmap()
```
`SOmanagement()` provides a number of contextual layers such as MPA boundaries and management zones.
```{r somap2, eval=TRUE}
SOmap(trim = -40) ## plot to 40S
## add the exclusive economic zones management layer
SOmanagement(eez = TRUE)
```
## Adding points
```{r somap_pts1, eval=TRUE}
## some longitude/latitude data
library(sp)
my_points_ll <- data.frame(lon = seq(0, 350, by = 10), lat = -55, z = runif(36))
coordinates(my_points_ll) <- c("lon", "lat")
projection(my_points_ll) <- "+proj=longlat +datum=WGS84"
```
This needs to be reprojected to match our map before plotting. The `SOproj` function does this:
```{r somap_pts2, eval=TRUE}
## reproject to our SOmap projection
my_points <- SOproj(my_points_ll)
## and plot
SOmap()
plot(my_points, col = "blue", add = TRUE)
```
Or use `SOplot` to reproject and plot in one step:
```{r somap_pts3, eval=TRUE}
SOmap()
SOplot(my_points_ll, col = "blue")
```
## Exercise 5
Why does `SOplot()` not need to use the projection? How does it know to plot the data correctly onto an existing plot?
### EX 5 ANSWER
<details><summary>EX 5 SOLUTION</summary>
<p>
The reason is that the `SOmap()` function *recorded the projection in use*. The functions to plot in SOmap are intended to be used in sequence, and by default we are adding map data or objects to an existing plot. The map projection in use is managed by these functions.
</p>
</details>
## Adding data layers
`SOmap()` builds a reasonable map on its own, and we can add a variety of layers to that.
```{r SOmap-add-data}
SOmap(trim = -30)
sst_local <- crop(rotate(sea_temp), extent(50, 180, -75, -30))
SOplot(sst_local)
sst_contours <- raster::rasterToContour(sst_local, levels = seq(0, 20, by = 2))
SOplot(sst_contours, add = TRUE)
```