base_map: Base Map

View source: R/base_map.R

base_mapR Documentation

Base Map

Description

fetches a basemap for our map based on the map's bounding box. Includes themes available at: https://leaflet-extras.github.io/leaflet-providers/preview/

Usage

base_map(bbox, increase_zoom = 0, basemap = "dark", nolabels = F)

Arguments

bbox

bounding box for out map extents generated using st_bbox() and expanded as necessary using expand_bbox(). Bounding box should be in lat/lng (epsg: 4326).

increase_zoom

the zoom is automatically calculated for the map but we can increase or decrease the zoom by setting an integer value.

basemap

the style of basemap to use. Currently supports 'dark', 'hydda', 'positron', 'voyager', 'wikimedia', 'mapnik', google, google-nobg, google-hybrid, google-terrain, google-satellite, google-road

nolabels

if TRUE, removes labels from the basemap. This is only available for some styles.

Value

a set of tiles to be added to a ggplot object.

Examples

# get bounding box for our map
library(sf)
bbox <- st_bbox(localauth_data)

# add to ggplot
library(ggplot2)
ggplot() +
  base_map(bbox, increase_zoom = 2, basemap = "google-terrain") +
  geom_sf(data = localauth_data, fill = NA) +
  coord_sf(xlim = c(bbox$xmin, bbox$xmax), ylim = c(bbox$ymin, bbox$ymax), crs = 4326)


# add straight to ggplot

ggplot() +
  base_map(st_bbox(localauth_data), increase_zoom = 2) +
  geom_sf(data = localauth_data, fill = NA)

Chrisjb/basemapR documentation built on April 1, 2022, 6:21 p.m.