res_local_map: Local Reserve Map

View source: R/res_local_map.R

res_local_mapR Documentation

Local Reserve Map

Description

Create a stylized reserve-level map for use with the reserve level reporting template

Usage

res_local_map(
  nerr_site_id,
  stations,
  bbox,
  shp,
  station_labs = TRUE,
  lab_loc = NULL,
  bg_map = NULL,
  zoom = NULL,
  maptype = "toner-lite"
)

Arguments

nerr_site_id

chr string of the reserve to make, first three characters used by NERRS

stations

chr string of the reserve stations to include in the map

bbox

a bounding box associated with the reserve. Must be in the format of c(X1, Y1, X2, Y2)

shp

sf data frame (preferred) or SpatialPolygons object

station_labs

logical, should stations be labeled? Defaults to TRUE

lab_loc

chr vector of 'R' and 'L', one letter for each station. if no lab_loc is specified then labels will default to the left.

bg_map

a georeferenced ggmap or ggplot object used as a background map, generally provided by a call to base_map. If bg_map is specified, maptype and zoom are ignored.

zoom

Zoom level for the base map created when bg_map is not specified. An integer value, 5 - 15, with higher numbers providing more detail. If not provided, a zoom level is autoscaled based on bbox parameters.

maptype

Background map type from Stamen Maps (http://maps.stamen.com/); one of c("terrain", "terrain-background", "terrain-labels", "terrain-lines", "toner", "toner-2010", "toner-2011", "toner-background", "toner-hybrid", "toner-labels", "toner-lines", "toner-lite", "watercolor").

Details

Creates a stylized, reserve-level base map. The user can specify the reserve and stations to plot. The user can also specify a bounding box. For multi-component reserves, the user should specify a bounding box that highlights the component of interest.

This function does not automatically detect conflicts between station labels. The lab_loc argument allows the user to specify "R" or "L" for each station to prevent labels from conflicting with each other.

This function is intended to be used with mapview::mapshot to generate a png for the reserve-level report.

Value

returns a ggplot object

Author(s)

Julie Padilla, Dave Eslinger

Examples

## a compact reserve
### set plotting parameters
stations <-
sampling_stations[(sampling_stations$NERR.Site.ID == 'elk'
          & sampling_stations$Status == 'Active'
          & sampling_stations$isSWMP == "P"), ]$Station.Code
          to_match <- c('wq', 'met')
stns <- stations[grep(paste(to_match, collapse = '|'), stations)]
shp_fl <- elk_spatial
bounding_elk <- c(-121.8005, 36.7779, -121.6966, 36.8799)
lab_dir <- c('L', 'R', 'L', 'L', 'L')
labs <- c('ap', 'cw', 'nm', 'sm', 'vm')

### Low zoom and default maptype plot (for CRAN testing, not recommended)
#    Lower zoom number gives coarser text and fewer features
(x_low <- res_local_map('elk', stations = stns, bbox = bounding_elk,
                   lab_loc = lab_dir, shp = shp_fl,
                   zoom = 10))


### Default zoom and maptype
x_def  <- res_local_map('elk', stations = stns, bbox = bounding_elk,
                   lab_loc = lab_dir, shp = shp_fl,
                   zoom = 10)

### A multicomponent reserve (show two different bounding boxes)
#    set plotting parameters
stations <- sampling_stations[(sampling_stations$NERR.Site.ID == 'cbm'
            & sampling_stations$Status == 'Active'
            & sampling_stations$isSWMP == "P"), ]$Station.Code
            to_match <- c('wq', 'met')
stns <- stations[grep(paste(to_match, collapse = '|'), stations)]
shp_fl <- cbm_spatial
bounding_cbm_1 <- c(-77.393, 38.277, -75.553, 39.741)
bounding_cbm_2 <- c(-76.8,  38.7, -76.62,  38.85)
lab_dir <- c('L', 'R', 'L', 'L', 'L')
labs <- c('ap', 'cw', 'nm', 'sm', 'vm')

### plot
y <- res_local_map('cbm', stations = stns, bbox = bounding_cbm_1,
                   lab_loc = lab_dir, shp = shp_fl)

z <- res_local_map('cbm', stations = stns, bbox = bounding_cbm_2,
                   lab_loc = lab_dir, shp = shp_fl)




SWMPrExtension documentation built on April 21, 2023, 1:14 a.m.