diff --git a/docs/404.html b/docs/404.html deleted file mode 100644 index 9df8cd8..0000000 --- a/docs/404.html +++ /dev/null @@ -1,125 +0,0 @@ - - -
- - - - -As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
-We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
-Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
-Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
-Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
-This Code of Conduct is adapted from the Contributor Covenant (http://contributor-covenant.org), version 1.0.0, available at http://contributor-covenant.org/version/1/0/0/
-vignettes/SOmap-introduction.Rmd
- SOmap-introduction.Rmd
This vignette was adapted from the SCAR-EGABI Tools for -Southern Ocean Spatial Analysis and Modelling course and Mapping in R -workshop.
-The oldest and most core general mapping package in R is the
-maps
package. It has a simple whole-world coastline data
-set for immediate use.
-maps::map()
The data underlying this live map is available by capturing the -output as an actual object. Notice that the coastline for Antarctica -does not extend to the south pole, and that parts of Russia that are -east of 180 longitude are not in the western part of the map.
-
-m <- maps::map(plot = FALSE)
-
-lonlat <- cbind(m$x, m$y)
-
-plot(lonlat, pch = "+", cex = 0.4, axes = FALSE)
-lines(lonlat, col = "dodgerblue")
-
-abline(h = c(-90, 90), v = c(-180, 180))
A very similar and more modern data set is available in the
-maptools
package.
This data set aligns exactly to the conventional -180/180 -90/90 -extent of the longitude/latitude projection.
-
-plot(0, type = "n", axes = FALSE, xlab = "", ylab = "", xlim = c(-180, 180), ylim = c(-90, 90))
-rect(xleft = -180, ybottom = -90, xright = 180, ytop = 90, border = "darkred", lwd = 4, lty = 2)
-plot(wrld_simpl, add = TRUE)
m
and the maptools data wrld_simpl
?Answer 1: range(m$x, na.rm = TRUE)
-range(m$y, na.rm = TRUE
) also m$range
Answer 2: polygon(lonlat, col = "grey")
does not work,
-and map(mp, fill = TRUE, col = "grey")
does not work, but
-maps::map(fill = TRUE, col = "grey")
does seem to work.
What’s going on? Look at the very south-eastern corner of the map. -The “coastline” has been extended to the very south boundary of the -available area.
-
-plot(0, type = "n", axes = FALSE, xlab = "", ylab = "", xlim = c(-150, 180), ylim = c(-90, -60))
-plot(wrld_simpl, add = TRUE, col = "grey")
-rect(xleft = -180, ybottom = -90, xright = 180, ytop = 90, border = "darkred", lwd = 4, lty = 2)
-
-maps::map(add = TRUE, col = "dodgerblue", lwd = 3)
When we add the old maps coastline see that it does not extend to 90S -and it does not traverse the southern boundary.
-One reason for this is that if we choose a projection where the east -and west edges of the Antarctic coastline meet then we get what looks a -fairly clean join.
-
-## scale factor
-f <- 3e6
-plot(rgdal::project(lonlat, "+proj=laea +lat_0=-90 +datum=WGS84"), asp = 1, type = "l",
- xlim = c(-1, 1) * f, ylim = c(-1, 1) * f, xlab = "", ylab = "")
If we try the same with wrld_simpl
it’s not as neat. We
-have a strange “seam” that points exactly to the south pole (our
-projection is centred on longitude = 0, and latitude = -90.
-plot(sp::spTransform(wrld_simpl, "+proj=laea +lat_0=-90 +datum=WGS84"), asp = 1,
- xlim = c(-1, 1) * f, ylim = c(-1, 1) * f, xlab = "", ylab = "", lwd = 3)
-abline(v = 0, h = 0, lty = 2, col = "grey")
In m
we have the maps data structure, and this looks
-promising.
-str(m)
-#> List of 4
-#> $ x : num [1:82403] -69.9 -69.9 -69.9 -70 -70.1 ...
-#> $ y : num [1:82403] 12.5 12.4 12.4 12.5 12.5 ...
-#> $ range: num [1:4] -180 190.3 -85.2 83.6
-#> $ names: chr [1:1627] "Aruba" "Afghanistan" "Angola" "Angola:Cabinda" ...
-#> - attr(*, "class")= chr "map"
-
-mp <- m
-pxy <- rgdal::project(lonlat, "+proj=laea +lat_0=-90 +datum=WGS84")
-mp$x <- pxy[,1]
-mp$y <- pxy[,2]
-mp$range <- c(range(mp$x,na.rm = TRUE), range(mp$y, na.rm = TRUE))
-mp$range
-#> [1] -12709814 12704237 -12576156 12470787
-plot(c(-1, 1) * f, c(-1, 1) * f, type = "n", asp = 1)
-maps::map(mp, add = TRUE)
-
-
-## but it doesn't take much to go awry
-plot(c(-1, 1) * f, c(-1, 1) * f, type = "n", asp = 1)
-maps::map(mp, add = TRUE, fill = TRUE, col = "grey")
The problem is that the maps database has enough internal structure
-to join lines correctly, with NA
gaps between different
-connected linestrings, but not enough to draw these things as polygons.
-A similar problem occurs in the default projection. While
-wrld_simpl
has been extend by placing two dummy coordinates
-at the east and west versions of the south pole, this data set does not
-have those.
We have to look quite carefully to understand what is happening, but -this is wrapping around overlapping itself and so close to the southern -bound we barely notice.
-
-plot(0, type = "n", axes = FALSE, xlab = "", ylab = "", xlim = c(-180, -110), ylim = c(-90, -60))
-
-rect(xleft = -180, ybottom = -90, xright = 180, ytop = 90, border = "darkred", lwd = 4, lty = 2)
-
-maps::map(add = TRUE,col = "grey", fill = TRUE)
-
-maps::map(col = "grey", fill = TRUE)
-
-
-mpmerc <- m
-pxy <- rgdal::project(lonlat, "+proj=merc +datum=WGS84")
-mpmerc$x <- pxy[,1]
-mpmerc$y <- pxy[,2]
-mpmerc$range <- c(range(mpmerc$x,na.rm = TRUE), range(mpmerc$y, na.rm = TRUE))
-mpmerc$range
-#> [1] -20037508 20037508 -20179524 18351859
-
-## the catastrophe made a little clearer
-plot(0, xlim = range(mpmerc$range[1:2]), ylim = c(mpmerc$range[1], 0))
-maps::map(mpmerc, fill = TRUE, col = "grey", add = TRUE)
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 in every circumstance, but
-the idea is that in most cases it should get you close enough, and if
-need be 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.
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 installing the SOmap
package if you haven’t
-done so already:
-remotes::install_github("AustralianAntarcticDivision/SOmap")
Then load the package:
-
-library(SOmap)
-#> Loading required package: raster
-## also define a colour map to use for some examples
-my_cmap <- colorRampPalette(c("#4D4140", "#596F7E", "#168B98", "#ED5B67",
- "#E27766", "#DAAD50", "#EAC3A6"))(51)
A basic circumpolar map in polar stereographic projection. Here we
-save our map to the base_plot
variable, so that we can use
-it again later without re-generating the map from scratch each time:
SOmanagement()
provides a number of contextual layers
-such as MPA boundaries and management zones.
-SOmap(trim = -40) ## plot to 40S
-## add the exclusive economic zones management layer
-SOmanagement(eez = 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"
Our data need to be reprojected to match our map before plotting. The
-SOproj
function does this:
-## reproject to our SOmap projection
-my_points <- SOproj(my_points_ll)
-## and plot
-plot(base_map)
-plot(my_points, col = "blue", add = TRUE)
Or use SOplot
to reproject and plot in one step:
First let’s construct some artificial raster data (in -longitude-latitude space) for demonstration purposes:
-
-library(raster)
-temp <- as.data.frame(expand.grid(lon = seq(100, 140, by = 0.25),
- lat = seq(-65, -45, by = 0.1)))
-temp$val <- sqrt((temp$lon - 120)^2/3 + (temp$lat - -40)^2/5)
-## create raster object
-xr <- rasterFromXYZ(temp)
-projection(xr) <- "+proj=longlat +datum=WGS84"
SOplot
will reproject and plot this for us:
The legend is out of character with the rest of the map. We can use
-SOleg
to fix that:
-## draw the base map
-plot(base_map)
-## add our raster
-SOplot(xr, legend = FALSE, col = my_cmap)
-## add the legend
-SOleg(xr, position = "topright", col = my_cmap, ticks = 6,
- type = "continuous", label = "My variable")
OK, well that worked but clearly the labels need tidying up. The
-easiest way is probably to set the number of decimal places in the label
-values via the rnd
parameter:
-plot(base_map)
-SOplot(xr, legend = FALSE, col = my_cmap)
-SOleg(xr, position = "topright", col = my_cmap, ticks = 6, rnd = 2,
- type = "continuous", label = "My variable")
Alternatively, we could explicitly set the colour range and -labels.
-
-## draw the base map
-plot(base_map)
-## add our raster, controlling the colour range to span the values 0 to 30
-colour_breaks <- seq(0, 30, length.out = length(my_cmap) + 1)
-SOplot(xr, legend = FALSE, col = my_cmap, breaks = colour_breaks)
-## add the legend, again controlling the colour range
-label_breaks <- seq(0, 30, length.out = 7)
-SOleg(position = "topright", col = my_cmap, breaks = label_breaks,
- type = "continuous", label = "My variable")
Note that if we don’t want to show the bathymetric legend, -we may run into problems:
-
-SOmap(bathy_legend = FALSE) ## suppress the bathy legend
-SOleg(position = "topright", col = my_cmap, breaks = label_breaks,
- type = "continuous", label = "My variable")
The legend has been chopped off because the layout has not left
-enough space around the map for the curved legend. There are a couple of
-ways around this. The elegant way is to specify
-bathy_legend = "space"
, which will leave appropriate space
-for a bathymetry legend but not actually plot it. This will also have
-the effect of leaving adequate space for other legends:
-SOmap(bathy_legend = "space")
-SOleg(position = "topright", col = my_cmap, breaks = label_breaks,
- type = "continuous", label = "My variable")
The second, rather hackier way is to generate the SOmap
-object with the bathymetric legend, but then remove the
-bathymetric legend before plotting:
-temp <- base_map
-temp$bathy_legend <- NULL ## remove the bathy legend
-plot(temp)
-SOleg(position = "topright", col = my_cmap, breaks = label_breaks,
- type = "continuous", label = "My variable")
See the Modifying map -objects section below for more details on modifying map objects.
-Multiple rasters:
- - -Let’s say that we have a large number of points that we wish to add -to the map. We could simply add them:
-
-points <- data.frame(lon = runif(1000, min = 30, max = 90), lat = runif(1000, min = -70, max = -50))
-plot(base_map)
-SOplot(x = points$lon, y = points$lat, pch = 19, col = 2)
However, the overlap of the points reduces the utility of the map.
-One option is to create a density layer, showing the number of points
-that fall into each cell of a raster grid. The SObin
-function can do this for us:
-plot(base_map)
-SObin(x = points$lon, y = points$lat, dim = c(100, 100),
- col = hcl.colors(100, "Viridis"), legend = FALSE, add = TRUE)
The SOmap_auto
function will take your input data and
-make a guess at an appropriate projection and extent to use. Note that
-this is not always going to guess the best projection and
-extent, so you should view it as a starting point from which you can
-generate a map to your exact requirements.
Use the elephant seal track data bundled with the package:
-
-ellie <- SOmap_data$mirounga_leonina
-## construct and plot the map
-SOmap_auto(ellie$lon, ellie$lat)
Just a blank map to which you could add other things:
-
-SOmap_auto(ellie$lon, ellie$lat, input_points = FALSE, input_lines = FALSE)
You can pass a raster as input data, but note that it won’t plot the -raster (it uses its extent to infer an appropriate extent for the -map):
-
-SOmap_auto(xr)
But we can add the raster if we wish:
-
-SOmap_auto(xr)
-SOplot(xr, col = my_cmap)
We can force a particular projection:
-
-SOmap_auto(xr, target = "laea", centre_lon = 147, centre_lat = -42)
-SOplot(xr, col = my_cmap)
Same but by supplying a full proj4 string to target
:
-SOmap_auto(xr, target = "+proj=laea +lat_0=-42 +lon_0=147")
-SOplot(xr, col = my_cmap)
See the -SOmap_auto vignette for more examples.
-The SOmap
and SOmap_auto
functions do their
-plotting using base graphics. If you are more comfortable working with
-ggplot2
, this is also possible. The SOgg
-function takes an object created by one of those functions (using base
-graphics) and converts it to use ggplot2
graphics instead.
-As with other SOmap
functions, this returns an object (of
-class SOmap_gg
or SOmap_auto_gg
) that contains
-all of the information needed to generate the map. Printing or plotting
-this object will cause it to construct a ggplot
object.
-Printing or plotting that object will cause it to be drawn to
-the graphics device, just like any other ggplot
object.
-myplotgg <- SOgg(base_map) ## creates a SOmap_gg object
-class(myplotgg)
-#> [1] "SOmap_gg"
-my_ggplot <- plot(myplotgg) ## creates a ggplot object
-class(my_ggplot)
-#> [1] "gg" "ggplot"
-plot(my_ggplot) ## plot it
Or in one step (this will cause myplot to be converted to SOmap’s -internal gg format, then a ggplot object constructed from that, then -that object will be plotted):
-
-SOgg(base_map)
The goal of SOmap
is to make it fairly easy to produce a
-fairly-good-looking map that will be adequate for most mapping
-requirements. It will never be possible to automatically produce a
-perfect map in every circumstance, but the aim is to
-have a low-effort way of getting fairly close most of the time.
This section describes some approaches to modifying a map to get it
-closer to your particular needs. Be warned: depending on the exact
-modifications needed, this might get you pretty close to the crumbling
-edge of SOmap
development. In particular, anything that
-requires modifying the internal structure of an SOmap
-object may change in the future (with luck, we’ll make this sort of
-thing easier - but we’re not there yet.)
Calls to SOmap()
, SOmanagement()
,
-SOmap_auto()
return an object of class SOmap
,
-SOmap_management
, or SOmap_auto
. These objects
-contain all of the data and plotting instructions required to draw the
-map. Calling print()
or plot()
on one of these
-objects will cause that code to be executed, and the object to be drawn
-in the current graphics device. Hence, calling SOmap()
-directly without assigning the result to a variable will make
-it appear in the graphics device, because the returned object is being
-printed to the console (and thus triggering the print
-method). But you can also assign the result to a variable,
-e.g. myplot <- SOmap()
and then explicitly plot the
-object with plot(myplot)
. The advantage of this is that you
-can potentially manipulate the myplot
object to make
-changes to the map before plotting it.
Note, this is likely to be fragile. Proceed at your own risk!
-
-mymap <- base_map
-names(mymap)
-#> [1] "projection" "target" "straight" "trim"
-#> [5] "bathy" "box" "plot_sequence" "coastline"
-#> [9] "ice" "outer_mask" "bathy_legend" "border"
The object contains a plot_sequence
component, which
-defines the order in which each part of the plot is drawn. The other
-components of the object contain the code required to draw each part.
-Take e.g. the ice component (this is the ice shelves, glacier tongues,
-etc). This is a list (in this case with only one element). Each element
-of the list is an object of class SO_plotter
, which is a
-SOmap-specific object that specifies a function to run along with
-arguments to pass to it:
-str(mymap$ice)
-#> List of 1
-#> $ :List of 2
-#> ..$ plotfun : chr "plot"
-#> ..$ plotargs:List of 4
-#> .. ..$ x :sfc_POLYGON of length 354; first list element: List of 1
-#> .. .. ..$ : num [1:5, 1:2] 1022981 1026000 1021994 1021935 1022981 ...
-#> .. .. ..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
-#> .. ..$ col : logi NA
-#> .. ..$ border: chr "black"
-#> .. ..$ add : logi TRUE
-#> ..- attr(*, "class")= chr "SO_plotter"
We can modify the function and/or its arguments:
-
-mymap$ice[[1]]$plotargs$col <- "green"
-plot(mymap)
We can remove entire components, either by setting the component to
-NULL
or removing its name from the
-plot_sequence
:
-temp <- mymap
-temp$coastline <- NULL ## set the coastline object to NULL
-temp$plot_sequence <- setdiff(temp$plot_sequence, "ice") ## remove "ice" from plot_sequence
-plot(temp) ## map without coastline or ice shown
But note that some elements are required. In particular, the
-bathymetry layer can’t currently be removed because the code that draws
-this is also the code that creates the plot page via
-plot.new()
. The code below would fail outright if there was
-no existing existing plot. If there was an existing plot in the graphics
-device, this code would run but give unpredictable results because it
-would draw on top of the previously-setup plot:
-## code not run here
-temp <- mymap
-temp$bathy <- NULL
-plot(temp)
One way around this would be to simply replace all of the bathymetric
-data values with NA
s. The plotting code would still have
-the extent of the bathymetric layer that it needs in order to set up the
-plot, but no data would be shown:
-temp <- mymap
-## the bathy data is held in temp$bathy[[1]]$plotargs$x
-## and it's a raster, so we can set its values to NA with
-raster::values(temp$bathy[[1]]$plotargs$x) <- NA_real_
-temp$bathy_legend <- NULL
-plot(temp)
We could also replace the bathymetry data with another raster object. -Note that we do need to be careful about the extent and projection of -this raster. For example, replacing the bathymetry raster with the ice -raster (which has the same polar stereographic projection but smaller -extent) gives:
-
-temp <- mymap
-temp$bathy[[1]]$plotargs$x <- ice
-temp$bathy_legend <- NULL
-plot(temp)
It’s chopped off because the extent of the ice raster is being used -to set the plot extent. But if we extend the ice raster to match the map -extent:
- - -A new function in SOmap version 0.6 is SOmerge
, which
-can take separate objects and combine them into a single map. For
-example:
-mymap <- SOmap(bathy_legend = "space")
-mylegend <- SOleg(x = runif(100), position = "topright", col = hcl.colors(80, "Viridis"),
- breaks = c(0.1, 0.2, 0.5, 0.9), trim = -45, label = "Thing",
- rnd = 1, type = "continuous")
-mymgmt <- SOmanagement(eez = TRUE, basemap = mymap)
-merged <- SOmerge(mymap, mymgmt, mylegend)
-plot(merged)
We can modify ggplot2
-based maps at two levels.
ggplot
object.
-Remember that printing or plotting a SOmap_gg
object
-produces a ggplot
object. This can be modified by adding
-e.g. layers or themes just like a normal ggplot
. Remember
-to load the ggplot2
library now that we are using
-ggplot2
functions directly.
-library(ggplot2)
-my_ggplot + geom_point(data = as.data.frame(my_points), aes(lon, lat, colour = z), size = 3) +
- scale_colour_distiller(palette = "Spectral")
Multiple rasters or multiple sets of points gets tricky if they are
-on different scales, because ggplot2
is only designed to
-work with a single colour scale per geometry type. However, the
-ggnewscale
package can be used to add multiple fill or
-colour scales.
-library(ggnewscale)
-plot(SOgg(SOmap(straight = TRUE))) +
- new_scale_fill() +
- geom_raster(data = as.data.frame(SOproj(xr), xy = TRUE),
- aes(x = x, y = y, fill = val)) +
- scale_fill_gradientn(colors = my_cmap, na.value = NA, name = "My variable")
SOmap_gg
object
-SOmap_gg
objects are similar in structure to
-SOmap
objects, in that they contain all of the data and
-plotting instructions required to draw the map:
-names(myplotgg)
-#> [1] "projection" "target" "straight" "trim"
-#> [5] "init" "bathy" "coord" "plot_sequence"
-#> [9] "scale_fill" "bathy_legend" "coastline" "ice"
-#> [13] "axis_labels" "theme" "border"
However, instead of base plotting functions, SOmap_gg
-objects use ggplot2
function calls, e.g.:
-myplotgg$ice[[1]]$plotfun
-#> [1] "ggplot2::geom_sf"
We can modify these functions and/or arguments in a similar manner to
-SOmap
objects.
-myplotgg$ice[[1]]$plotargs$fill <- "green"
-plot(myplotgg)
Or remove the bathymetric raster layer:
-
-temp <- myplotgg
-temp$bathy <- NULL
-temp$bathy_legend <- NULL
-plot(temp)
Or replace it with a different raster (use the ice
-raster as an example):
-temp <- myplotgg
-## convert ice raster to suitable data.frame
-ice_raster_as_df <- raster::as.data.frame(SOproj(ice), xy = TRUE)
-names(ice_raster_as_df)[3] <- "ice"
-## add this to our object in place of bathy
-temp$bathy <- SO_plotter(plotfun = "ggplot2::geom_raster",
- plotargs = list(data = ice_raster_as_df,
- mapping = aes_string(fill = "ice")))
-## change the colour scale
-temp$scale_fill[[1]]$plotargs <- list(colours = my_cmap, na.value = "#FFFFFF00", guide = "none")
-## remove the bathy legend
-temp$bathy_legend <- NULL
-plot(temp)
Some other things worth noting.
-If you type a variable/object name directly into the console then it
-triggers that object’s print
method automatically. Typing
-SOmap()
at the console returns an object of class
-SOmap
, and because it’s happening at the console that
-object’s print
method is called, which causes the map to be
-plotted in the current graphics device.
However, R turns off automatic printing inside for
loops
-and functions. So this code:
-for (i in 1:5) {
- SOmap_auto()
-}
won’t produce anything, because the print
method never
-gets called. If you are generating maps using loops, you will need to
-explicitly call the print
method:
-for (i in 1:5) {
- print(SOmap_auto())
-}
When constructing maps, we commonly want to show features like -oceanographic fronts, ice extent, coastline, place names, and MPA -boundaries. There are a few sources of such data:
-SOmap
, see the
-SOmap::SOmap_data
objectvignettes/many-automap-examples.Rmd
- many-automap-examples.Rmd
-library(SOmap)
-#> Loading required package: raster
-#> Loading required package: sp
-
-# lonrange, latrange
-# lonvec, latvec
-# sp, sf object
-# raster, stars object
-# file
-
-
-set.seed(1)
-SOmap_auto()
-SOmap_auto(target = "+proj=laea +lat_0=-20 +ellps=WGS84")
-llx <- c(100, 120)
-lly <- c(-60, -30)
-SOmap_auto(llx, lly)
-SOmap_auto(llx, lly, target = NULL)
-SOmap_auto(cbind(llx, lly), target = NULL)
-SOmap_auto(SOmap_data$mirounga_leonina$lon, SOmap_data$mirounga_leonina$lat, target = "laea")
-SOmap_auto(SOmap_data$mirounga_leonina$lon, SOmap_data$mirounga_leonina$lat, centre_lon = 147)
-
-SOmap_auto(SOmap_data$mirounga_leonina$lon, SOmap_data$mirounga_leonina$lat, target = NULL)
-## causes crash for yet-to-be-investigated reasons
-SOmap_auto(ice)
-## causes crash for yet-to-be-investigated reasons
-SOmap_auto(ice, target = "laea", centre_lon = 147, centre_lat = -42)
-SOplot(ice, col = palr::ice_pal(100))
-## causes crash for yet-to-be-investigated reasons
-SOmap_auto(ice, centre_lon = 147, centre_lat = -42)
-SOplot(ice, col = palr::ice_pal(100))
-## causes crash for yet-to-be-investigated reasons
-SOmap_auto(ice, target = "merc", centre_lon = 147, centre_lat = -42)
-SOplot(ice, col = palr::ice_pal(100))
-SOmap_auto(x = c(10, 60), y = c(-40, -70))
-SOmap_auto(x=c(10,60), y=c(-40,-70), trim_background = FALSE)
-#> Warning in SOmap_auto_inner(x = x, y = y, centre_lon = centre_lon, centre_lat =
-#> centre_lat, : 'trim_background' argument to SOmap() is defunct
-x <- cbind(c(runif(50, -180, -160), runif(50, 160, 180)), runif(100, -65, -30))
-SOmap_auto(x)
-#> Warning in warp_in_memory_gdal_cpp(x, source_WKT = source_projection, target_WKT
-#> = projection, : GDAL Error 2: gdalwarpoperation.cpp, 1845: cannot allocate
-#> 29859840008 bytes
-x <- cbind(c(runif(50, -180, -130), runif(50, 130, 180)), runif(100, -65, -30))
-SOmap_auto(x)
-#> Warning in warp_in_memory_gdal_cpp(x, source_WKT = source_projection, target_WKT
-#> = projection, : GDAL Error 2: gdalwarpoperation.cpp, 1845: cannot allocate
-#> 29859840008 bytes
-x <- cbind(c(runif(50, -180, -160), runif(50, 130, 180)), runif(100, -65, -30))
-SOmap_auto(x)
-#> Warning in warp_in_memory_gdal_cpp(x, source_WKT = source_projection, target_WKT
-#> = projection, : GDAL Error 2: gdalwarpoperation.cpp, 1845: cannot allocate
-#> 29859840008 bytes
Handle missing values in input data.
-temporarily turn this off …
-
-data("albatross", package = "adehabitatLT")
-## convert the albatross data to a single matrix of lon, lat points
-albatrack <- do.call(rbind, lapply(albatross, function(z) rgdal::project(rbind(as.matrix(z[, c("x", "y")]), NA), "+proj=utm +zone=42 +south +datum=WGS84", inv = TRUE)))
-
-## construct the map and return it, but don't plot it
-alb_map <- SOmap_auto(albatrack[, 1], albatrack[, 2])
-alb_map
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.
-The development version from GitHub with:
-
-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")
To make a simple map you can use the following function; use ? SOmap
to see all the options for modifying layers.
There is also SOmanagement()
which provides management layers for the Southern Ocean and SOleg()
which gives custom rounded legends for added map layers.
-## 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.
-
-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.
-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.
-data("albatross", package = "adehabitatLT")
-## convert the albatross data to a single matrix of lon, lat points
-albatrack <- do.call(rbind, lapply(albatross, function(z) rgdal::project(rbind(as.matrix(z[, c("x", "y")]), NA), "+proj=utm +zone=42 +south +datum=WGS84", inv = TRUE)))
-
-## 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:
-
-alb_map$pcol <- "blue"
-## plot it
-alb_map
We could also decide we want a reversed bathymetry color and cyan lines between the dots.
-
-# 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
:
-## 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)
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 just map it!
.
-set.seed(1)
-amap <- SOmap_auto(input_points = FALSE, input_lines = FALSE)
-amap
To add data to this plot we can just do so.
-
-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()
.
-SOcrs()
-#> [1] "+proj=stere +lon_0=-36.8427233395983 +lat_0=-76.5139986273002 +lat_ts=71 +datum=WGS84"
Many objects can be reprojected with SOproj()
, including the map objects themselves.
-
-prj <- "+proj=laea +lat_0=-90 +lon_0=147 +datum=WGS84"
-## reproject a raster
-SOproj(ice, target = prj)
-#> class : RasterLayer
-#> dimensions : 342, 326, 111492 (nrow, ncol, ncell)
-#> resolution : 32837.52, 31606.02 (x, y)
-#> extent : -5430639, 5274392, -5534313, 5274946 (xmin, xmax, ymin, ymax)
-#> crs : +proj=laea +lat_0=-90 +lon_0=147 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
-#> source : memory
-#> names : nt_20181015_f18_nrt_s.bin
-#> values : 2.059468, 100 (min, max)
-
-## 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. By contributing to this project, you agree to abide by its terms.
-NEWS.md
- SOauto_map()
function and class is now defunct, replaced by SOmap_auto()
.Arguments mask
and trim_background
now removed from SOmap_auto()
.
Argument buffer
removed from SOmap_auto()
, changed expand
to numeric fraction (expand = 0
equivalent to old expand = FALSE
).
Argument sample_type
to SOmap_auto()
moved to internal function automap_nothing()
.
New internal functions to become the engine behind SOmap_auto()
, automap_maker()
to create a background extent from disparate inputs, and automap_nothing()
to create a background by random data.
New auto extent logic for SOmap_auto()
to address #30.
New reproj::reproj
methods for SOmap_auto
and SOmap
classes.
Bathymetric data reprocessed from the GEBCO_2014 Grid data set.
-data(Bathy)
An object of class "RasterLayer"
The GEBCO_2014 Grid, version 20150318
-SOmap
and similar objects contain all of the data and code required to draw a map. This information is embedded in SO_plotter
objects within the SOmap
object.
SO_plotter(plotfun, plotargs = NULL, name = NULL)
function or string: either the name of a function to use, or the function itself
list: arguments to pass to the function
string: optional name for this element
An object of class SO_plotter
-SOmap
if (FALSE) {
- p <- SOmap()
- ## replace the `box` element with different plotting code
- p$box <- SO_plotter(plotfun = "graphics::box", plotargs = list(col = "red"))
-
- ## you can also specify multiple plotting instructions for a single graphical element
- ## of a map
- p$box <- c(SO_plotter(plotfun = "graphics::box", plotargs = list(col = "red")),
- SO_plotter(plotfun = "graphics::box", plotargs = list(lwd = 2)))
-}
-
R/SOauto_crop.r
- SOauto_crop.Rd
Reproject and crop Spatial and sf objects to SOmap objects
-SOauto_crop(layer, x, sp = TRUE)
: an sf
or Spatial
(SpatialPolygonsDataFrame, SpatialLinesDataFrame, SpatialPointsDataFrame etc) object to reproject and crop
: a SOmap or SOauto_map object
logical: if TRUE
, return the cropped object in Spatial
form, otherwise sf
If successful, a reprojected and cropped version of layer
. If the reprojection or cropping operations fail, the returned object will be of class try-error
. If the cropping operations return an empty object (i.e. no parts of layer
lie within the bounds of x
) then the returned object will either be NULL
(if sp = TRUE
) or an sf
object with no features if sp = FALSE
.
Creates a raster density layer from a set of points.
-SObin(
- x,
- y = NULL,
- baselayer = NULL,
- ...,
- col = hcl.colors(26, "Viridis"),
- dim = c(512, 512),
- add = TRUE,
- target = NULL,
- source = NULL,
- data.frame = FALSE
-)
longitudes
latitudes
optional spatial layer to get extent from
passed to plot if add = TRUE
colours to use if add = TRUE
dimensions of raster to bin to
if TRUE
, the raster is added to the current plot. An error is thrown if there is no existing plot
target projection passed to SOproj
source projection of data projection passed to SOproj
if true return a data frame instead of a raster.
A raster. If add = TRUE
, it is returned invisibly.
SOmap_auto()
-pts <- geosphere::randomCoordinates(1e6)
-bin <- SObin(pts[, 1], pts[, 2], add = TRUE)
-
-
This is thoroughly experimental!
-SOcode(x, data_object_name = "SOmap_data")
: a map object as returned by SOmap, SOmanagement, SOleg, or SOgg
string: the name to use for the object that will hold the map data. See Examples, below
A list with two elements: code
contains R code that will draw the map, and SOmap_data
(or whatever was passed as the data_object_name
argument) contains any data required by that code
if (FALSE) {
- p <- SOmap()
- mapcode <- SOcode(p, data_object_name = "SOmap_data")
-
- ## write this code to a file
- my_R_file <- tempfile(fileext = ".R")
- writeLines(mapcode$code, con = my_R_file)
-
- ## you can edit the code in that file if desired
-
- ## save the data
- my_data_file <- tempfile(fileext = ".rds")
- saveRDS(mapcode$SOmap_data, my_data_file)
-
- ## later on, we can re-load the data and execute the code
- SOmap_data <- readRDS(my_data_file)
- source(my_R_file)
-
- ## or just to show that this works, evaluate the returned code directly against its data
- with(mapcode, for (codeline in code) eval(parse(text = codeline)))
-}
-
-
Set or return the coordinate system currently in use.
-SOcrs(crs = NULL)
provide PROJ string to set the value
If argument crs
is NULL, the function returns the current value (which may be NULL
).
if (FALSE) {
-SOmap()
-SOcrs()
-}
-
Note: this function is still experimental! Use at your own risk.
-SOgg(...)
: one or more objects as returned by SOmap
, SOmap2
, SOmanagement
, or SOmap_auto
An object of class "SOmap_gg", "SOmanagement_gg", or "SOmap_auto_gg". Printing or plotting this object will cause it to generate a ggplot2 object, which will be returned to the user. If this object is printed or plotted (e.g. to the console) then it will be displayed in the current graphics device as is usual for ggplot2 objects.
-if (FALSE) {
- ## generate a SOmap object
- p <- SOmap2(trim = -45, iwc = TRUE, iwc_labels = TRUE, graticules = TRUE, fronts = TRUE,
- mpa = TRUE, mpa_labels = TRUE)
-
- ## convert this to a ggplot2-based representation
- pg <- SOgg(p)
-
- ## display it
- pg
-
- ## we can see that this object has a bunch of ggplot code embedded inside of it
- str(pg)
-
- ## and that code can be modified if desired
- ## e.g. change the bathymetry colours
- pg$scale_fill[[1]]$plotargs$colours <- topo.colors(21)
- ## plot it
- pg
-
- ## If we want to change the legend breaks we can add breaks to the plotting arguments.
- pg$scale_fill[[1]]$plotargs$breaks <- c(0,500,1000,4000)
-
-
- ## when the print or plot method is called on pg, it creates an actual ggplot2
- ## object, which we can capture and modify
- pg_gg <- plot(pg)
- class(pg_gg)
-
- ## modifying this is done in the same way any other ggplot object is modified
- ## e.g. add a new scale_fill_gradientn to override the existing one
- pg_gg + ggplot2::scale_fill_gradientn(colours = heat.colors(21))
-}
-
-
Text size in base graphics is generally specified via cex
values, which are multipliers applied to the device pointsize. SOgg_cex
is a convenience function that converts a cex value into a size
value as used by ggplot2 geometries.
SOgg_cex(cex)
numeric: character expansion, see par
The corresponding 'size' value to use in ggplot calls
-Rounded legends for SOmap
-SOleg(
- x = NULL,
- position = "topright",
- col = NULL,
- ticks = NULL,
- tlabs = NULL,
- breaks = NULL,
- trim = -45,
- type = "discrete",
- label = "",
- ladj = 0.5,
- lsrt = 0,
- lcex = 0.75,
- tadj = 0.5,
- tcex = 1,
- rnd = NULL,
- border_width = 2
-)
numeric: object to obtain min and max values from for type = "continuous"
.
string: where you want the legend ("topleft", "topright", "bottomleft", or "bottomright").
character: colours to use.
numeric: number of ticks to include on the legend. Only used with type = "continuous"
.
character: tick labels. Required for type = "discrete"
, optional for type = "continuous"
if x
is given.
numeric: vector of tick positions for type = "continuous"
when x
is given.
numeric: trim
value that was used to create the SOmap object (see SOmap
).
string: type of legend ("discrete" or "continuous").
string: legend label.
numeric: distance to adjust the tick labels from the ticks.
numeric: angle of the tick labels.
numeric: size of the tick labels.
numeric: distance to adjust the title from the ticks.
numeric: size of the title text.
numeric: optional rounding factor for continuous legends using the link{round}
function.
numeric: thickness (in degrees of latitude) of the border.
An object of class "SOmap_legend". Printing or plotting this object will cause it to be added to the SOmap in the current graphics device.
-if (FALSE) {
- SOmap()
-
- ## Discrete Legend
- SOleg(position = "topleft", col = hcl.colors(5, "Viridis"),
- tlabs = c("a", "b", "c", "d", "e"), trim = -45, label = "Species")
-
- ## Continuous Legend
- SOleg(x = runif(100), position = "topright", col = hcl.colors(80, "Viridis"),
- breaks = c(0.1, 0.2, 0.5, 0.9), trim = -45, label = "Species",
- rnd = 1, type = "continuous")
-}
-
Function for adding management layers to SOmap
-SOmanagement(
- ccamlr = FALSE,
- ccamlr_labels = FALSE,
- ssru = FALSE,
- ssru_labels = FALSE,
- ssmu = FALSE,
- ssmu_labels = FALSE,
- rb = FALSE,
- rb_labels = FALSE,
- sprfmorb = FALSE,
- trim = -45,
- eez = FALSE,
- eez_labels = FALSE,
- mpa = FALSE,
- mpa_labels = FALSE,
- iwc = FALSE,
- iwc_labels = FALSE,
- domains = FALSE,
- domains_labels = FALSE,
- rb_col = "green",
- sprfmo_col = "grey50",
- ccamlr_col = "red",
- ssru_col = "grey50",
- ssmu_col = "grey70",
- eez_col = "maroon",
- mpa_col = "yellow",
- iwc_col = "blue",
- domains_col = "magenta",
- basemap
-)
logical: if TRUE
, insert the CCAMLR area boundaries.
logical: if TRUE
, add labels for the CCAMLR areas.
logical: if TRUE
, insert the CCAMLR small scale research unit boundaries.
logical: if TRUE
, add labels for the CCAMLR small scale research units.
logical: if TRUE
, insert the CCAMLR small scale management unit boundaries.
logical: if TRUE
, add labels for the CCAMLR small scale management units.
logical: if TRUE
, insert the CCAMLR research block boundaries.
logical: if TRUE
, add labels for the CCAMLR research blocks.
logical: if TRUE
, insert the SPRFMO toothfish research block boundaries.
numeric: latitude to trim the map to. Set this to -10 for effectively no trim.
logical: if TRUE
, insert Exclusive Economic Zones.
logical: if TRUE
, add labels for the Exclusive Economic Zones.
logical: if TRUE
, insert CCAMLR Marine Protected Areas.
logical: if TRUE
, add labels for the CCAMLR Marine Protected Areas.
logical: if TRUE
, insert International Whaling Commission boundaries.
logical: if TRUE
, add labels for the International Whaling Commission areas.
logical: if TRUE
, insert CCAMLR Marine Protected Areas planning domains.
logical: if TRUE
, add labels for the CCAMLR Marine Protected Area planning domains.
character: colour for CCAMLR research blocks.
character: colour for SPRFMO toothfish research blocks
character: colour for CCAMLR boundaries
character: colour for CCAMLR small scale research units.
character: colour for CCAMLR small scale management units.
character: colour for Exclusive Economic Zone boundaries.
character: colour for CCAMLR Marine Protected Areas.
character: colour for IWC boundaries.
character: colour for the CCAMLR planning domains boundaries.
SOmap or SOmap_auto: optional map object to extract extent, projection, and other information from.
An object of class "SOmap_management" containing the requested management layers. Printing or plotting this object will display those layers on the current map (note that an SOmap
object needs to have been plotted first)
if (FALSE) {
- tfile <- tempfile("SOmap", fileext = ".png")
- png(tfile, width=22, height=20, units='cm', res=600)
- SOmap(trim = -45)
- SOmanagement(ccamlr = TRUE, ccamlr_labels = TRUE, trim=-45)
- dev.off()
- unlink(tfile)
-
- ## map with non-default latitudinal extent
- SOmap(trim = -55)
- ## either provide the same extent via 'trim'
- SOmanagement(ccamlr = TRUE, ccamlr_labels = TRUE, trim = -55)
-
- ## or equivalently, pass the basemap to SOmanagement
- x <- SOmap(trim = -55)
- plot(x)
- SOmanagement(ccamlr = TRUE, ccamlr_labels = TRUE, basemap = x)
-}
-
Removed from SOmap
-default_somap(...)
-
-SOauto_map(...)
all arguments passed to new function
Create publication-quality Southern Ocean maps in a simple manner with multiple management layer options.
-Function for creating round Southern Ocean maps.
-SOmap(
- bathy_legend = TRUE,
- border = TRUE,
- trim = -45,
- graticules = FALSE,
- straight = FALSE,
- land = TRUE,
- land_col = "black",
- ice = TRUE,
- ice_col = "black",
- fronts = FALSE,
- fronts_col = c("hotpink", "orchid", "plum"),
- border_col = c("white", "black"),
- border_width = 2,
- graticules_col = "grey70"
-)
logical: if TRUE
, insert the bathymetry legend. If bathy_legend = NULL
or bathy_legend = "space"
, then space will be left for the legend but no legend will actually be plotted. Use this if you plan to add a legend later.
logical: if TRUE
, insert longitude border.
numeric: latitude to trim the map to. Set this to -10 for effectively no trim.
logical: if TRUE
, insert graticule grid.
logical: if TRUE
, leave a blank space on the side for a straight legend.
logical: if TRUE
, plot coastline.
character: colour to use for coastline.
logical: if TRUE
, plot ice features (ice shelves, glacier tongues, and similar).
character: colour to use for ice features.
logical or string: if TRUE
or "Orsi", plot Orsi et al., (1995) ocean fronts: Subantarctic Front, Polar Front, Southern Antarctic Circumpolar Current Front. If "Park" plot the Park & Durand (2019) fronts; Northern boundary, Subantarctic Front, Polar Front, Southern Antarctic Circumpolar Current Front and Southern Boundary.
character: colours for fronts.
character: colours for longitude border.
numeric: thickness (in degrees of latitude) of the border.
string: colour for graticule grid.
An object of class "SOmap", which represents a polar-stereographic map of the southern hemisphere. Printing or plotting this object will cause it to be displayed in the current graphics device.
-Function for creating round Southern Ocean maps with inbuild base layers.
-SOmap2(
- bathy_legend = TRUE,
- land = TRUE,
- ice = TRUE,
- ccamlr = FALSE,
- ccamlr_labels = FALSE,
- ssru = FALSE,
- ssru_labels = FALSE,
- ssmu = FALSE,
- ssmu_labels = FALSE,
- rb = FALSE,
- rb_labels = FALSE,
- sprfmorb = FALSE,
- border = TRUE,
- trim = -45,
- graticules = FALSE,
- eez = FALSE,
- eez_labels = FALSE,
- mpa = FALSE,
- mpa_labels = FALSE,
- domains = FALSE,
- domains_labels = FALSE,
- iwc = FALSE,
- iwc_labels = FALSE,
- straight = FALSE,
- fronts = FALSE,
- fronts_col = c("hotpink", "orchid", "plum"),
- land_col = "black",
- ice_col = "black",
- rb_col = 3,
- sprfmo_col = "grey50",
- ccamlr_col = 2,
- ssru_col = "grey50",
- ssmu_col = "grey70",
- eez_col = "maroon",
- mpa_col = "yellow",
- border_col = c("white", "black"),
- graticules_col = "grey70",
- iwc_col = "blue",
- domains_col = "magenta"
-)
logical: if TRUE
, insert the bathymetry legend.
logical: if TRUE
, plot the coastline.
logical: if TRUE
, plot ice features (ice shelves, glacier tongues, and similar).
logical: if TRUE
, insert the CCAMLR area boundaries.
logical: if TRUE
, add labels for the CCAMLR areas.
logical: if TRUE
, insert the CCAMLR small scale research unit boundaries.
logical: if TRUE
, add labels for the CCAMLR small scale research units.
logical: if TRUE
, insert the CCAMLR small scale management unit boundaries.
logical: if TRUE
, add labels for the CCAMLR small scale management units.
logical: if TRUE
, insert the CCAMLR research block boundaries.
logical: if TRUE
, add labels for the CCAMLR research blocks.
logical: if TRUE
, insert the SPRFMO toothfish research block boundaries.
logical: if TRUE
, insert longitude border.
numeric: latitude to trim the map to. Set this to -10 for effectively no trim.
logical: if TRUE
, insert a graticule grid.
logical: if TRUE
, insert Exclusive Economic Zones.
logical: if TRUE
, add labels for the Exclusive Economic Zones.
logical: if TRUE
, insert CCAMLR Marine Protected Areas.
logical: if TRUE
, add labels for the CCAMLR Marine Protected Areas.
logical: if TRUE
, insert CCAMLR Marine Protected Areas planning domains.
logical: if TRUE
, add labels for the CCAMLR Marine Protected Area planning domains.
logical: if TRUE
, insert International Whaling Commission boundaries.
logical: if TRUE
, add labels for the International Whaling Commission areas.
logical: if TRUE
, leave a blank space on the side for a straight legend.
logical or string: if TRUE
or "Orsi", plot Orsi et al., (1995) ocean fronts: Subantarctic Front, Polar Front, Southern Antarctic Circumpolar Current Front. If "Park" plot the Park & Durand (2019) fronts; Northern boundary, Subantarctic Front, Polar Front, Southern Antarctic Circumpolar Current Front and Southern Boundary.
character: colours to use for fronts.
character: colour to use for coastline.
character: colour to use for ice features.
character: colour for CCAMLR research blocks.
character: colour for SPRFMO toothfish research blocks
character: colour for CCAMLR boundaries
character: colour for CCAMLR small scale research units.
character: colour for CCAMLR small scale management units.
character: colour for Exclusive Economic Zone boundaries.
character: colour for CCAMLR Marine Protected Areas.
character: colours for longitude border.
character: colour for graticule grid.
character: colour for IWC boundaries.
character: colour for the CCAMLR planning domains boundaries.
An object of class "SOmap", which represents a polar-stereographic map of the southern hemisphere, with the chosen management layers added. Printing or plotting this object will cause it to be displayed in the current graphics device.
-if (FALSE) {
- SOmap2(ccamlr = TRUE, mpa = TRUE, trim = -45)
-}
-
Given some minimal input information, SOmap_auto
will attempt to guess an appropriate extent and projection to use. For demonstration purposes, run the function without any inputs at all and it will use random location data.
SOmap_auto(
- x,
- y,
- centre_lon = NULL,
- centre_lat = NULL,
- target = "stere",
- dimXY = c(512, 512),
- bathy = TRUE,
- land = TRUE,
- land_col = "black",
- ice = TRUE,
- ice_col = "black",
- input_points = TRUE,
- input_lines = TRUE,
- graticule = TRUE,
- expand = 0.05,
- contours = FALSE,
- levels = c(-500, -1000, -2000),
- ppch = 19,
- pcol = 2,
- pcex = 1,
- bathyleg = FALSE,
- llty = 1,
- llwd = 1,
- lcol = 1,
- gratlon = NULL,
- gratlat = NULL,
- gratpos = "all",
- ...
-)
optional input data longitudes. x
can also be a Raster
or Spatial
object, in which case the extent of x
will be used for the map, but note that the contents of x
will not be plotted automatically (use SOplot
to do so)
optional input data latitudes
optional centre longitude (of the map projection, also used to for plot range if expand = TRUE
)
as per centre_lon
optional projection family (default is stere
ographic), or full PROJ string (see Details)
dimensions of background bathmetry (if used), a default is provided
logical: if TRUE
, plot bathymetry. Alternatively, provide the bathymetry data to use as a Raster
object
logical: if TRUE
, plot coastline. Alternatively, provide the coastline data to use as a Spatial
object
character: colour to use for plotting the coastline
logical: if TRUE
, plot ice features (ice shelves, glacier tongues, and similar)
character: colour to use for ice features
add points to plot (of x, y)
add lines to plot (of x, y)
flag to add a basic graticule
fraction to expand plot range (default is 0.05, set to zero for no buffer, may be negative)
logical: add contours?
numeric: contour levels to use if contours
is TRUE
set point character (default=19)
set point color (default=19)
set point cex (default=1)
optional bathymetry legend (default=FALSE)
set line type
set line width
set line color
longitude values for graticule meridians
latitude values for graticule parallels
positions (sides) of graticule labels
reserved, checked for defunct and deprecated usage
An object of class SOmap_auto, containing the data and other details required to generate the map. Printing or plotting the object will cause it to be plotted.
-To input your data, use input locations as x
(longitude) and y
(latitude) values. There must be at least two locations. The x
input object can also be provided as a Raster
or Spatial
object, in which case the extent of x
will be used for the map, but note that the contents of x
will not be plotted automatically (use SOplot
to do so).
Try target
families such as 'lcc', 'laea', 'gnom', 'merc', 'aea' if feeling adventurous.
if (FALSE) {
- SOmap_auto(c(0, 50), c(-70, -50))
- SOmap_auto(runif(10, 130, 200), runif(10, -80, -10))
- SOplot(c(147, 180), c(-42, -60), pch = 19, cex = 2,col = "firebrick")
- SOmap_auto(runif(10, 130, 200), runif(10, -85, -60))
-
- ## save the result to explore later!
- protomap <- SOmap_auto(runif(10, 60, 160), runif(10, -73, -50))
-
- SOmap_auto(runif(50, 40, 180), runif(50, -73, -10), family = "laea", centre_lat = -15,
- input_lines = FALSE)
-}
-
Various spatial datasets that are commonly used on Southern Ocean maps.
-data(SOmap_data)
A list containing the following elements:
CCAMLR_MPA
Description: current marine protected areas
Source: CCAMLR
URL: https://data.ccamlr.org/dataset/marine-protected-areas
License: not specified
CCAMLR_research_blocks
Description: A defined spatial area in which research fishing on toothfish is conducted under a research plan agreed by the Commission
Source: CCAMLR
URL: https://data.ccamlr.org/dataset/research-blocks
License: Not specified
CCAMLR_SSMU
Description: Small-scale management units (SSMUs) are designed to be used as a basis for subdividing the precautionary catch limit for krill in Subareas 48.1, 48.2, 48.3 and 48.4, and in developing management procedures for the krill fishery that can adequately account for localised effects on krill predators (SC-CAMLR-XXI, paragraphs 3.16 to 3.18). The boundaries of the SSMUs are based on predator foraging ranges (refer SC-CAMLR-XXI, Annex 4 and Trathan et al, 2008).
Source: CCAMLR
URL: https://data.ccamlr.org/dataset/small-scale-management-units
License: Not specified
CCAMLR_SSRU
Description: Small-scale research units (SSRUs) are designed to be used as a basis for subdividing the precautionary catch limit for toothfish in exploratory fisheries, and in condcuting research fishing and developing stock assessments. The boundaries of the SSRUs are defined in Conservation Measure 41-01 (2013). CCAMLR Secretariat (2013).
Source: CCAMLR
URL: https://data.ccamlr.org/dataset/small-scale-research-units
License: Not specified
CCAMLR_statistical_areas
Description: Statistical areas, subareas and divisions are used globally for the purpose of reporting fishery statistics. CCAMLR's Convention Area in the Southern Ocean is divided, for statistical purposes, into Area 48 (Atlantic Antarctic) between 70W and 30E, Area 58 (Indian Ocean Antarctic) between 30 and 150E, and Area 88 (Pacific Antarctic) between 150E and 70W. These areas, which are further subdivided into subareas and divisions, are managed by CCAMLR.
Source: CCAMLR
URL: https://data.ccamlr.org/dataset/statistical-areas-subareas-and-divisions
License: Public domain
CCAMLR_VME_polygons
Description: Defined areas of registered vulnerable marine ecosystems as defined under CM 22-09.
Source: CCAMLR
URL: https://gis.ccamlr.org/geoserver/ows?service=wfs&version=1.0.0&request=GetCapabilities
License: Not specified
CCAMLR_VME_fsr
Description: Vulnerable marine ecosystem fine-scale rectangles identified under CM 22-07.
Source: CCAMLR
URL: https://gis.ccamlr.org/geoserver/ows?service=wfs&version=1.0.0&request=GetCapabilities
License: Not specified
CCAMLR_VME_risk_areas
Description: Vulnerable marine ecosystem risk areas declared under CM 22-07.
Source: CCAMLR
URL: https://gis.ccamlr.org/geoserver/ows?service=wfs&version=1.0.0&request=GetCapabilities
License: Not specified
CCAMLR_planning_domains
Description: Nine planning domains were defined during the 2011 CCAMLR workshop on marine protected areas (SC-CAMLR-XXX, Annex 6). These planning domains provide comprehensive coverage of bioregions in the Southern Ocean and may be used as reporting and auditing units for work related to the development of MPAs and as a means to organise future activities related to this effort.
Source: CCAMLR
URL: https://gis.ccamlr.org/geoserver/ows?service=wfs&version=1.0.0&request=GetCapabilities
License: Not specified
continent
Description: Coastline, details TBA
Source: TBA
URL: TBA
License: TBA
EEZ
Description: An exclusive economic zone (EEZ) is a sea zone prescribed by the United Nations Convention on the Law of the Sea over which a state has special rights regarding the exploration and use of marine resources.
Source: Flanders Marine Institute (2020). Union of the ESRI Country shapefile and the Exclusive Economic Zones (version 3). https://doi.org/10.14284/403
URL: https://www.marineregions.org/
License: CC-BY
fronts_orsi
Description: Southern Ocean fronts as defined by Orsi et al. 1995
Source: orsifronts
URL: https://github.com/AustralianAntarcticDivision/orsifronts
License: see orsifronts
seaice_feb and seaice_oct
Description: median October and February sea ice extent
Source: Fetterer, F., K. Knowles, W. Meier, M. Savoie, and A. K. Windnagel. 2017, updated daily. Sea Ice Index, Version 3. Boulder, Colorado USA. NSIDC: National Snow and Ice Data Center
URL: https://doi.org/10.7265/N5K072F8
License: Please cite
mirounga_leonina
Description: Example elephant seal Argos tracking data
Source: Data were sourced from the Integrated Marine Observing System (IMOS) - IMOS is supported by the Australian Government through the National Collaborative Research Infrastructure Strategy and the Super Science Initiative
URL: https://github.com/ianjonsen/bsam
License: Please cite
ADD_coastline_med
Description: Medium-resolution coastline data from the SCAR Antarctic Digital Database. This coastline only covers continental Antarctica: see the GSHHS_i_L1 data for the remainder of the southern hemisphere
Source: SCAR
URL: https://add.data.bas.ac.uk/repository/entry/show?entryid=f477219b-9121-44d6-afa6-d8552762dc45
License: CC-BY. Citation: SCAR Antarctic Digital Database (2018)
GSHHS_i_L1
Description: Coastline data (excluding Antarctica) from the Global Self-consistent, Hierarchical, High-resolution Geography Database. Only southern hemisphere, level 1 (boundary between land and ocean, except Antarctica), intermediate resolution data are included here
Source: Wessel P, Smith WHF (1996) A Global Self-consistent, Hierarchical, High-resolution Shoreline Database. J. Geophys. Res. 101:8741-8743
URL: http://www.soest.hawaii.edu/wessel/gshhg/
License: LGPL
fronts_park
Description: Altimetry-derived Antarctic Circumpolar Current fronts
Source: Park Young-Hyang, Durand Isabelle (2019). Altimetry-drived Antarctic Circumpolar Current fronts. SEANOE.
URL: https://doi.org/10.17882/59800
License: CC-BY-4.0, please cite in full as at DOI
text
, that passes x[[labelcol]]
to text
as the labels
parameterR/SOmanagement.R
- SOmap_text.Rd
Helper function for labels
-This is basically a thin wrapper around text
, that passes x[[labelcol]]
to text
as the labels
parameter
SOmap_text(x, labelcol, ...)
data.frame, Spatial data.frame, or sfc: data to pass to text
string: name of the column in x
to use for text labels
other plot arguements
as for text
The inputs must contain exactly one object of class SOmap
.
SOmerge(..., reproject = TRUE)
: one or more objects of class SOmap
, SOmap_management
, or SOmap_legend
, or a list of such objects
logical: if TRUE
(the default), and any of the input objects are in a different projection to the input SOmap
object, an attempt will be made to reproject them. If you run into problems with SOmerge
, try setting this to FALSE
A single object of class SOmap
.
Note that objects of class SOmap_auto
are not yet supported.
if (FALSE) {
- mymap <- SOmap(bathy_legend = "space")
- mylegend <- SOleg(x = runif(100), position = "topright", col = hcl.colors(80, "Viridis"),
- breaks = c(0.1, 0.2, 0.5, 0.9), trim = -45, label = "Thing",
- rnd = 1, type = "continuous")
- mymgmt <- SOmanagement(eez = TRUE, basemap = mymap)
- merged <- SOmerge(mymap, mymgmt, mylegend)
- plot(merged)
-
- ## note that you need to take some care in constructing the component objects
- ## to ensure their visual consistency
-
- ## e.g. this will work, but the EEZ layers will extend beyond the map bounds
- mymap <- SOmap(trim = -55)
- mymgmt <- SOmanagement(eez = TRUE, trim = -45) ## note different trim
- plot(SOmerge(mymap, mymgmt))
-
- ## better to do
- mymap <- SOmap(trim = -55)
- mymgmt <- SOmanagement(eez = TRUE, basemap = mymap)
- plot(SOmerge(mymap, mymgmt))
-
- ## SOmerge will reproject objects on the fly if needed
-
- sw_atlantic <- SOmap_auto(c(-70, -20), c(-65, -45), input_points = FALSE, input_lines = FALSE)
- mymap_auto$projection
- ## the EEZs within this region
- sw_atlantic_mgmt <- SOmanagement(eez = TRUE, basemap = sw_atlantic)
-
- mymap <- SOmap()
- mymap$projection
-
- ## sw_atlantic_mgmt lies within the bounds of mymap, so we might want to combine them
- ## even though their projections are different
- merged <- SOmerge(mymap, sw_atlantic_mgmt)
- plot(merged)
-}
-
-
Reproject and add an object to an existing SOmap
or SOmap_auto
.
SOplot(x, y = NULL, target = NULL, ..., source = NULL, add = TRUE)
: longitude vector, or an object with coordinates
: latitude vector, or missing if x is an object
: target projection. If not provided, it will default to the projection of the current map, and if that is not set it will use the default SOmap polar stereographic projection
: other parameters passed to the plot
function
: if x
is not an object with a projection already set, specify its projection here (default = longlat)
logical: if TRUE
, add this object to an existing plot
if (FALSE) {
- x <-c (-70, -60,-50, -90)
- y <-c (-50, -75, -45, -60)
- map <- SOmap_auto(x, y, input_lines = FALSE)
-
- ## plot the map, with the x, y points already added
- map
- ## re-plot the points in a different colour and marker
- SOplot(x = x, y = y, pch = 0, cex = 2, col = 6)
-}
-
Function for reprojecting data.
-SOproj(x, y = NULL, target = NULL, data, ..., source = NULL)
longitude vector, or object with coordinates
latitude vector
target projection (default = stereo)
optional data to be included
arguments passed to reproj::reproj() function
starting projection (default = longlat)
Reprojects the given data object to polar projection. Works with Points, spatial, raster, SOmap, sf and sfc objects.
-Example sea ice concentration data from the Southern Ocean (2018-10-15). -(See "data-raw/ice.R").
-if (FALSE) {
- ll <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
- xy <- coordinates(spTransform(as(SOmap_data$fronts_orsi, "SpatialPoints"), ll))
- ## just because you can doesn't mean you should ...
- SOmap_auto(xy[,1], xy[,2], bathy = ice, input_points = FALSE, levels = c(15, 30, 60, 90))
-}
-
- All functions- - |
- |
---|---|
- - | -Bathymetric data for maps |
-
- - | -Construct a SO_plotter object |
-
- - | -Reproject and crop Spatial and sf objects to SOmap objects |
-
- - | -Bin longitude latitude points by count in a SOmap context |
-
- - | -Extract plotting code from a SOmap |
-
- - | -SOmap coordinate system |
-
- - | -Generate a ggplot2 representation of an SOmap object |
-
- - | -Convert cex to ggplot size |
-
- - | -Rounded legends for SOmap |
-
- - | -Southern Ocean management map layers |
-
- - | -Defunct function |
-
- - | -SOmap |
-
- - | -Southern Ocean Map |
-
- - | -Southern Ocean Map 2 |
-
- - | -Custom Southern Ocean map |
-
- - | -Contextual data for Southern Ocean maps |
-
- - | -Helper function for labels
-This is basically a thin wrapper around |
-
- - | -Merge multiple SOmap or related objects |
-
- - | -Add items to an existing SOmap |
-
- - | -Southern projection |
-
- - | -Sea ice |
-
- - | -used in SOleg to test color palettes |
-
- - | -Latitude mask for polar rasters. |
-
-
|
- Reproject SOmap |
-
used in SOleg to test color palettes
-is.discrete(x)
Object to test for is it discrete
returns true false
-Latitude mask for polar projections; written by M.D. Sumner and part of the spex package.
-latmask(x, latitude = 0, southern = TRUE)
A raster layer.
maximum latitude (effectively a minimum latitude if southern = FALSE)
flag for whether south-polar context is used, default is TRUE
if (FALSE) {
-## assumes that you have already defined a raster object called 'ice'
-plot(latmask(ice, -60))
-}
-
Reproject a SOmap object by specifying a 'target' projection string (PROJ4)
-# S3 method for SOmap
-reproj(x, target, ..., source = NULL)
-
-# S3 method for SOmap_auto
-reproj(x, target, ..., source = NULL)
-
-# S3 method for SOmap_management
-reproj(x, target, ..., source = NULL)
-
-# S3 method for SOmap_legend
-reproj(x, target, ..., source = NULL)
-
-# S3 method for BasicRaster
-reproj(x, target, ..., source = NULL)
-
-# S3 method for Spatial
-reproj(x, target, ..., source = NULL)
-
-# S3 method for sf
-reproj(x, target, ..., source = NULL)
-
-# S3 method for sfc
-reproj(x, target, ..., source = NULL)
coordinates
target specification (PROJ.4 string or epsg code)
arguments passed to the underlying projection engine, see reproj::reproj()
source specification (PROJ.4 string or epsg code)
See reproj::reproj()
for details.
So many ...
-if (FALSE) {
- set.seed(27)
- amap <- SOmap_auto()
- reproj(amap, "+proj=moll")
- reproj(amap, "+proj=laea +lat_0=-55 +lon_0=154 +datum=WGS84")
-
- bmap <- SOmap(trim = -35)
-
- ## works great!
- reproj(bmap, "+proj=stere +lat_0=-90 +lon_0=147 +lat_ts=-71 +datum=WGS84")
-
- ## these aren't exactly ideal
- reproj(bmap, "+proj=ortho +lat_0=-70")
- reproj(bmap, "+proj=laea +lat_0=-55 +lon_0=154 +datum=WGS84")
-}
-