Learn R Programming

AirMonitor (version 0.4.2)

monitor_leaflet: Leaflet interactive map of monitor locations

Description

This function creates interactive maps that will be displayed in RStudio's 'Viewer' tab. The slice argument is used to collapse a mts_monitor timeseries into a single value. If slice is an integer, that row index will be selected from the monitor$data dataframe. If slice is a function (unquoted), that function will be applied to the timeseries with the argument na.rm=TRUE (e.g. max(..., na.rm=TRUE)).

If slice is a user defined function, it will be used with argument na.rm=TRUE to collapse the time dimension. Thus, user defined functions must accept na.rm as an argument.

Usage

monitor_leaflet(
  monitor,
  slice = "max",
  radius = 10,
  opacity = 0.7,
  maptype = "terrain",
  extraVars = NULL,
  jitter = 5e-04,
  NAAQS = c("PM2.5_2024", "PM2.5"),
  ...
)

Value

Invisibly returns a leaflet map of class "leaflet".

Arguments

monitor

mts_monitor object.

slice

Either a formatted time string, a time index, the name of a (potentially user defined) function used to collapse the time axis.

radius

radius of monitor circles

opacity

opacity of monitor circles

maptype

optional name of leaflet ProviderTiles to use, e.g. "terrain"

extraVars

Character vector of additional column names from monitor$meta to be shown in leaflet popups.

jitter

Amount to use to slightly adjust locations so that multiple monitors at the same location can be seen. Use zero or NA to see precise locations.

NAAQS

Version of NAAQS levels to use. See Note.

...

Additional arguments passed to leaflet::addCircleMarker().

Details

The maptype argument is mapped onto leaflet "ProviderTile" names. Current map types include:

"roadmap"

-- "OpenStreetMap"

"satellite"

-- "Esri.WorldImagery"

"terrain"

-- "Esri.WorldTopoMap"

"toner"

-- "Stamen.Toner"

If a character string not listed above is provided, it will be used as the underlying map tile if available. See https://leaflet-extras.github.io/leaflet-providers/ for a list of "provider tiles" to use as the background map.

Examples

Run this code
if (FALSE) {
library(AirMonitor)
# Fail gracefully if any resources are not available
try({

# Maximum AQI category at each site
monitor_loadLatest() %>%
  monitor_filter(stateCode %in% CONUS) %>%
  monitor_leaflet()

# Mean AQI category at each site
monitor_loadLatest() %>%
  monitor_filter(stateCode %in% CONUS) %>%
  monitor_leaflet(
    slice = "mean"
  )

# Mean AQI category at each site using the updated NAAQS
monitor_loadLatest() %>%
  monitor_filter(stateCode %in% CONUS) %>%
  monitor_leaflet(
    slice = "mean",
    NAAQS = "PM2.5_2024"
  )

}, silent = FALSE)
}

Run the code above in your browser using DataLab