In the above
package on GitHub, installed via:
require(devtools)
install_github("ABoVE-AotM/above")
There is a new function called getBasemapRaster
, which obtains an RGB raster from any of the available base maps in the (incredible!) open source leaflet package. It is meant to replace - in a way - the ggmap function, which now requires an API key with Google.
It is in several ways an improvement on ggmap
: You can set the lat and long limits strictly; It returns a projected raster which can be reprojected in any way you like; It can access any of the remarkable diversity of high quality mapping option at: http://leaflet-extras.github.io/leaflet-providers/preview/.
Note, however, that it creates a “png” and “html” and places it in a given directory, and does not delete them by default.
require(above)
SEalaska.topo <- getBasemapRaster(-138,-130, 56, 60, "OpenTopoMap")
Note that high resolution rasters are reduced in rendering within R by default … this can be modified with plotRGB options.
The output of the file is a projected raster:
SEalaska.topo
## class : RasterBrick
## dimensions : 2469, 2152, 5313288, 4 (nrow, ncol, ncell, nlayers)
## resolution : 0.003717472, 0.001620089 (x, y)
## extent : -138, -130, 56, 60 (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
## data source : in memory
## names : basemap.1, basemap.2, basemap.3, basemap.4
## min values : 0, 0, 0, 255
## max values : 255, 255, 248, 255
If you prefer ggplotting, there is a function in the RStoolbox
package called ggRGB
. For some reason, it chooses to plot the layers backwards (blue, green, red), so you need to change that order with the 1,2,3 below. Note, also, unless you reproject the raster to a better coordinate system, that the defaule fixed aspect ratio will be a distortion.
ggRGB(SEalaska.topo, 1, 2, 3, coord_equal = FALSE)
Here are some BC Atlin woodland caribou data, downloaded from movebank and processed:
load("BCATLINC.df.rda")
str(caribou.df)
## Classes 'movetrack' and 'data.frame': 16270 obs. of 8 variables:
## $ id : Factor w/ 10 levels "238689385","238689395",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ time : POSIXct, format: "2000-01-10 19:00:41" "2000-01-10 23:00:39" ...
## $ lon : num -133 -133 -133 -133 -133 ...
## $ lat : num 60 60 60 60 60 ...
## $ x : num -1939505 -1937351 -1937189 -1937150 -1937071 ...
## $ y : num 2803043 2802492 2801960 2801858 2801859 ...
## $ nickname: Factor w/ 10 levels "BCAC1","BCAC2",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ study : chr "ABoVE: BC Atlin Caribou" "ABoVE: BC Atlin Caribou" "ABoVE: BC Atlin Caribou" "ABoVE: BC Atlin Caribou" ...
## - attr(*, "metadata")=List of 6
## ..$ study : chr "ABoVE: BC Atlin Caribou"
## ..$ projection : chr "+proj=lcc +lat_1=50 +lat_2=70 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"
## ..$ dateDownloaded: chr "2018-11-23 14:45:52"
## ..$ citation : chr "Polfus JL, Heinemeyer K, Hebblewhite M, Taku River Tlingit First Nation (2014) Comparing traditional ecological"| __truncated__
## ..$ license : chr "Data are for use only as part of NASA's Arctic-Boreal Vulnerability Experiment (ABoVE)."
## ..$ dailymean : logi FALSE
We’ll get an RGB raster - using Esri.WorldPhysical
as a backdrop:
range(caribou.df$lat)
## [1] 59.1335 60.1857
range(caribou.df$lon)
## [1] -133.8643 -132.3781
BCatlin.map <- getBasemapRaster(-134,-132,59,60.3, "Esri.WorldImagery", plotme = FALSE)
ggRGB(BCatlin.map, 1, 2, 3, coord_equal = FALSE) +
geom_path(data = caribou.df, aes(lon, lat, col = nickname)) + scale_colour_hue(l = 80)