Polar maps!
Last time we got this far by creating a very simplistic polar map and discussing some of the difficulties in customizing and finishing it. Since then Dale Maschette discussed these problems at useR Brisbane 2018 and stirred up multiple discussions on twitter about the joys of polar maps.
Behold SOmap.
SOmap::SOmap()
## Loading required namespace: rgeos
SOmap
To install the SOmap package use
remotes::install_github("AustralianAntarcticDivision/SOmap")
and see the package readme and documentation for further details.
Creating a polar map is as easy as the following.
library(SOmap)
pmap <- SOmap()
pmap
To add our own data to the map we can use the SOplot()
function, by default this function is geared to adding data to our existing map.
pmap
longitudes <- seq(-180, 175, by = 5)
latitudes <- approx(c(-48, -88, -48), n = length(longitudes))$y
SOplot(longitudes, latitudes, pch = 1:25)
## No projection provided, assuming longlat
The great feature here is that we only needed our data, points in longitude and latitude and a single call to SOplot()
- the data is automtically added to the plot in the right way and works much like base plot().
To start afresh from SOmap()
above we can print()
the object.
We can also add spatial types to the plot.
print(pmap)
SOplot(SOmap_data$seaice_oct)
SOplot(SOmap_data$seaice_feb, col = "firebrick", lwd = 2, lty = 2)
In the previous post we had these desired features.
- a local, specific, extent (this is surprisingly difficult to get right)
- a “graticule”, i.e. lines of constant longitude and latitude
- other data on the map, again this can be suprisingly complicated
- labels
- aesthetics and scales for the data on the map
- accoutrements (scale bars and north arrow and the fancy white-black margin real maps use)
The extent is controlled by the data we give SOauto_map()
, this also adapts the map projection in use to best suit the data given.
grid <- expand.grid(x= seq(105, 165, by = 5), y = seq(-75, -38, by = 8))
amap <- SOauto_map(grid$x, grid$y)
By default, the input data are plotted as points and as joined lines. The lines don’t make sense here, so turn them off.
(amap <- SOauto_map(grid$x, grid$y, input_lines = FALSE))
As well as our very contrived set of grid points, more realistic data works as well.
track <- SOmap::SOmap_data$mirounga_leonina
trackmap <- SOauto_map(track$lon, track$lat, pcol = "yellow")
trackmap
While SOplot()
provides the arguments for the plot method in use, SOmap()
and SOauto_map()
provide special argumens that match their base equivalents for points and lines, i.e. pcol
and lcol
respectively.
We see immediately that the seal heading west raced home somewhat more quickly than its easterly counterpart.
SOauto_map(track$lon, track$lat, pcol = colourvalues::colour_values(track$date))
library(dplyr)
track %>% group_by(id) %>%
summarize(start = min(date), end =max(date), west = min(lon), east = max(lon))
## # A tibble: 2 x 5
## id start end west east
## <chr> <dttm> <dttm> <dbl> <dbl>
## 1 ct96-05-13 2013-03-15 11:21:41 2013-09-18 16:44:36 69.7 116.
## 2 ct96-09-13 2013-03-06 23:01:11 2013-08-24 23:37:25 31.3 70.6
Exploring projections
The default projection family is +proj=stere
. It is a family because while this is a Polar Stereographic projection the actual details include a central longitude, central latitude, latitude of true-scale, ellipsoid and datum, and many others. If we change any of these parameters from their defaults we have a completely different map projection. There is a literal infinity of possible Polar Stereographic projections, though in practice we tend to use only a handful.
There are other families, Lambert Azimuthal Equal Area +proj=laea
, Lambert Conformal Conic +proj=lcc
, Gnomonic +proj=gnom
, Mercator +proj=merc
, Equidistant Cylindrical +proj=eqc
, Mollweide +proj=moll
, Oblique Mercator +proj=omerc
, and many more. Another good catalogue of projections is the d3 software readme.
Some of these familes may be specified simply by name, and the map will be automatically configured to centre on the input data.
SOauto_map(track$lon, track$lat, family = "lcc")
#title(main = "Lambert Conformal Conic")
SOauto_map(track$lon, track$lat, family = "laea")
We can control the map projection centre if required.
SOauto_map(track$lon, track$lat, family = "laea", centre_lon = 120, centre_lat = -80)
Not everything will work, or work well - but this is an easy way to explore what kind of projection is sensible for our data.
SOauto_map(track$lon, track$lat, family = "moll")
SOauto_map(track$lon, track$lat, family = "gnom")
## Warning in rgdal::rawTransform(projfrom, projto, nrow(xy), xy[, 1], xy[, :
## 225 projected point(s) not finite
SOauto_map(track$lon, track$lat, family = "merc")
Some projections require extra parameters, and those can be controlled precisely by setting family
directly as a full projection string. In this case the centre_lon
and centre_lat
values will be ignored.
SOauto_map(track$lon, track$lat, family = "+proj=omerc +lon_1=40 +lon_2=120 +lonc=90 +lat_1=-40 +lat_2=-70")
…
Twitter
Google+
Facebook
Reddit
LinkedIn
StumbleUpon
Email