forked from Maschette/SOmap
-
Notifications
You must be signed in to change notification settings - Fork 6
/
README.Rmd
178 lines (120 loc) · 6.31 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
---
output: github_document
editor_options:
chunk_output_type: console
---
[![R-CMD-check](https://github.com/AustralianAntarcticDivision/SOmap/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/AustralianAntarcticDivision/SOmap/actions/workflows/R-CMD-check.yaml)
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", warning = FALSE,
fig.path = "man/figures/README-", fig.height = 8, fig.width = 8, dpi = 300, out.width = "100%")
```
# SOmap <img src="man/figures/logo.png" align="right" />
The goal of SOmap is to make publication quality round Southern Ocean maps in polar projections with little effort. This package is still very much a work in progress contact me with any questions or suggestions.
## Installation
The development version from [GitHub](https://github.com/AustralianAntarcticDivision/SOmap) with:
```{r eval = FALSE}
install.packages("SOmap", repos = c(SCAR = "https://scar.r-universe.dev",
CRAN = "https://cloud.r-project.org"))
## or
## install.packages("remotes") ## if needed
remotes::install_github("AustralianAntarcticDivision/SOmap")
```
## Example
To make a simple map you can use the following function; use `? SOmap` to see all the options for modifying layers.
```{r examplemap, message = FALSE, warning = FALSE}
library(SOmap)
SOmap()
```
There is also `SOmanagement()` which provides management layers for the Southern Ocean and `SOleg()` which gives custom rounded legends for added map layers.
```{r management}
## custom colours
spiritedMedium <- colorRampPalette(c("#4D4140", "#596F7E", "#168B98",
"#ED5B67", "#E27766", "#DAAD50", "#EAC3A6"))
spirited <- spiritedMedium(80)
SOmap(trim = -40)
## add an example sea ice raster, which is bundled with SOmap
plot(ice, col = spirited, add = TRUE, legend = FALSE, alpha = 0.95)
SOleg(ice, position = "topright", col = spirited, ticks = 6,
tlabs = c("0", "20", "40", "60", "80", "100"),
trim = -40, label = "Sea Ice", type = "continuous")
## add the exclusive economic zones management layer
SOmanagement(eez = TRUE)
```
Curved legends can be either continuous (as above) or discrete.
```{r, echo=FALSE}
centroids<-data.frame(pop = structure(1:8, .Label = c("1", "2", "3","4", "5", "6", "7", "8"), class = "factor"), lon = c(7.36921794861538, 76.0083253690476, 88.1945661849315, 134.966444407778, -178.009759,-164.882487618519, -80.8082988510345, -30.1700251934884), lat = c(-63.6191794892308,-53.1358253619048, -65.0577956330822, -65.0150925555556, -72.891637562451, -63.3747530640741, -68.9245057482759, -60.3177015502326))
coordinates(centroids)<-c("lon", "lat")
projection(centroids)<- "+proj=longlat +datum=WGS84"
centroids<-spTransform(centroids,CRS(projection(SOmap::Bathy)))
```
```{r SOleg}
spirited8 <- spiritedMedium(8)
SOmap()
plot(centroids, col=spirited8, add=TRUE, pch=19)
SOleg(centroids,position = "topright", col = spirited8, ticks = 8,
tlabs =1:8, label = "Centroids", type = "discrete")
```
An **automatic** plot function `SOmap_auto()` will take any data in the form of longitude and latitude vectors and create a guess at a map.
```{r automap, fig.height = 5, fig.width = 5}
ellie <- SOmap_data$mirounga_leonina
## construct and plot the map
SOmap_auto(ellie$lon, ellie$lat)
```
The `SOmap_auto()`, `SOmap()`, and `SOmap2()` functions return the data used to make the map so that further customization can be made. Plotting or printing the returned object will cause the map to be displayed in the graphics device.
```{r automap2, fig.height = 5, fig.width = 5}
data("albatross", package = "adehabitatLT")
## convert the albatross data to a single matrix of lon, lat points
albatrack <- do.call(rbind, lapply(albatross, function(z) terra::project(rbind(as.matrix(z[, c("x", "y")]), NA), from = "+proj=utm +zone=42 +south +datum=WGS84", to = "EPSG:4326")))
## construct the map and return it, but don't plot it
alb_map <- SOmap_auto(albatrack[, 1], albatrack[, 2])
```
Modifying this map object is currently a rather experimental process (proceed at your own risk!) but, for example, if we wished to change the points to be blue rather than red:
```{r automap3, fig.height = 5, fig.width = 5}
alb_map$pcol <- "blue"
## plot it
alb_map
```
We could also decide we want a reversed bathymetry color and cyan lines between the dots.
```{r automap4, fig.height = 5, fig.width = 5}
# change the line color
alb_map$lcol <- "cyan"
# reverse the bathymetry
alb_map$bathy_palette<-rev(alb_map$bathy_palette)
## plot it
alb_map
```
Objects from `sf`, `sp`, or `raster` can also be used, but note that they will be used for their extents only and will not automatically be plotted. But we can plot them easily with `SOplot`:
```{r automap-spatial, fig.height = 5, fig.width = 5}
## use the bundled fronts data as an example
mydata <- SOmap_data$fronts_orsi
SOmap_auto(mydata, target = "laea", centre_lon = 147)
SOplot(mydata, col = 2)
```
## Easy projections
`SOmap` goes with the philosophy "we actually rather like ourselves, and care about our experience" and so there are some easy ways to work with projections, and <quote>just map it!</quote>.
```{r auto-setup}
set.seed(1)
amap <- SOmap_auto(input_points = FALSE, input_lines = FALSE)
amap
```
To add data to this plot we can just do so.
```{r just-map-it}
amap
SOplot(SOmap_data$seaice_oct, lwd = 3, col = "blue", lty = 2)
```
`SOplot()` will add data by default, and can take spatial objects or even raw longitude and latitude values (we like you). When a plot is set up the *coordinate reference system* used is recorded so that we can use it again. The projection *currently in use* is always available by running `SOcrs()`.
```{r}
SOcrs()
```
Many objects can be reprojected with `SOproj()`, including the map objects themselves.
```{r raster}
prj <- "+proj=laea +lat_0=-90 +lon_0=147 +datum=WGS84"
## reproject a raster
SOproj(ice, target = prj)
## reproject a SOmap
SOproj(amap, target = prj)
```
Note that we must assume raw input is "longitude/latitude", and the function will issue a warning.
---
Please note that the SOmap project is released with a [Contributor Code of Conduct](https://australianantarcticdivision.github.io/SOmap/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.