| Title: | Create Maps of Air Pollution Data |
|---|---|
| Description: | Combine the air quality data analysis methods of 'openair' with the JavaScript 'Leaflet' (<https://leafletjs.com/>) library. Functionality includes plotting site maps, "directional analysis" figures such as polar plots, and air mass trajectories. |
| Authors: | Jack Davison [cre, aut] (ORCID: <https://orcid.org/0000-0003-2653-6615>), David Carslaw [aut] (ORCID: <https://orcid.org/0000-0003-0991-950X>) |
| Maintainer: | Jack Davison <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.10.1.9000 |
| Built: | 2026-10-19 13:50:52 UTC |
| Source: | https://github.com/openair-project/openairmaps |
This function is similar (but not identical to) the leaflet::addMarkers()
and leaflet::addCircleMarkers() functions in leaflet, which allows users
to add openair directional analysis plots to any leaflet map and have more
control over groups and layerIds than in "all-in-one" functions like
polarMap().
addPolarMarkers( map, pollutant, fun = openair::polarPlot, lng = NULL, lat = NULL, layerId = NULL, group = NULL, popup = NULL, popupOptions = NULL, label = NULL, labelOptions = NULL, options = leaflet::markerOptions(), clusterOptions = NULL, clusterId = NULL, key.position = "none", d.icon = 200, d.fig = 3.5, alpha = 1, progress = TRUE, data = leaflet::getMapData(map), ... ) addPolarDiffMarkers( map, pollutant, before = leaflet::getMapData(map), after = leaflet::getMapData(map), lng = NULL, lat = NULL, layerId = NULL, group = NULL, popup = NULL, popupOptions = NULL, label = NULL, labelOptions = NULL, options = leaflet::markerOptions(), clusterOptions = NULL, clusterId = NULL, key.position = "none", d.icon = 200, d.fig = 3.5, alpha = 1, progress = TRUE, ... )addPolarMarkers( map, pollutant, fun = openair::polarPlot, lng = NULL, lat = NULL, layerId = NULL, group = NULL, popup = NULL, popupOptions = NULL, label = NULL, labelOptions = NULL, options = leaflet::markerOptions(), clusterOptions = NULL, clusterId = NULL, key.position = "none", d.icon = 200, d.fig = 3.5, alpha = 1, progress = TRUE, data = leaflet::getMapData(map), ... ) addPolarDiffMarkers( map, pollutant, before = leaflet::getMapData(map), after = leaflet::getMapData(map), lng = NULL, lat = NULL, layerId = NULL, group = NULL, popup = NULL, popupOptions = NULL, label = NULL, labelOptions = NULL, options = leaflet::markerOptions(), clusterOptions = NULL, clusterId = NULL, key.position = "none", d.icon = 200, d.fig = 3.5, alpha = 1, progress = TRUE, ... )
map |
a map widget object created from |
pollutant |
The name of the pollutant to be plot. Note that, if |
fun |
An |
lng |
The decimal longitude. |
lat |
The decimal latitude. |
layerId |
the layer id |
group |
the name of the group the newly created layers should belong to
(for |
popup |
A column of |
popupOptions |
A Vector of |
label |
A column of |
labelOptions |
A Vector of |
options |
a list of extra options for tile layers, popups, paths (circles, rectangles, polygons, ...), or other map elements |
clusterOptions |
if not |
clusterId |
the id for the marker cluster layer |
key.position |
Passed to |
d.icon |
The diameter of the plot on the map in pixels. This will affect
the size of the individual polar markers. Alternatively, a vector in the
form |
d.fig |
The diameter of the plots to be produced using |
alpha |
The desired opacity of the polar markers. Can also be set via
|
progress |
Show a progress bar while the markers are created? |
data |
A data frame. The data frame must contain the data to plot your
choice of openair directional analysis plot, which includes wind speed
( |
... |
Other arguments for the plotting function (e.g. |
before, after
|
A data frame that represents the before/after case. See
|
A leaflet object.
addPolarMarkers(): Add any one-table polar marker (e.g.,
openair::polarPlot())
addPolarDiffMarkers(): Add the two-table openair::polarDiff() marker.
shiny::runExample(package = "openairmaps") to see examples of this
function used in a shiny::shinyApp()
## Not run: library(leaflet) library(openair) # different types of polar plot on one map leaflet(data = polar_data) |> addTiles() |> addPolarMarkers( "ws", fun = openair::windRose, annotate = FALSE, group = "Wind Rose" ) |> addPolarMarkers("nox", fun = openair::polarPlot, group = "Polar Plot") |> addLayersControl( baseGroups = c("Wind Rose", "Polar Plot") ) # use of polar diff (NB: both 'before' and 'after' inherit from `leaflet()`, # so at least one should be overridden - in this case 'after') leaflet(data = polar_data) |> addTiles() |> addPolarDiffMarkers("nox", after = dplyr::mutate(polar_data, nox = jitter(nox, 5)) ) ## End(Not run)## Not run: library(leaflet) library(openair) # different types of polar plot on one map leaflet(data = polar_data) |> addTiles() |> addPolarMarkers( "ws", fun = openair::windRose, annotate = FALSE, group = "Wind Rose" ) |> addPolarMarkers("nox", fun = openair::polarPlot, group = "Polar Plot") |> addLayersControl( baseGroups = c("Wind Rose", "Polar Plot") ) # use of polar diff (NB: both 'before' and 'after' inherit from `leaflet()`, # so at least one should be overridden - in this case 'after') leaflet(data = polar_data) |> addTiles() |> addPolarDiffMarkers("nox", after = dplyr::mutate(polar_data, nox = jitter(nox, 5)) ) ## End(Not run)
This function is similar (but not identical to) the leaflet::addRectangles()
function in leaflet, which allows users to add gridded trajectory
statistics (calculated using openair::trajLevel()) to any leaflet map and
have more control over groups and layerIds than in "all-in-one" functions
like trajLevelMap().
addTrajLevel( map, data = leaflet::getMapData(map), lng = "lon", lat = "lat", pollutant = NULL, statistic = "frequency", percentile = 90, lon.inc = 1, lat.inc = 1, breaks = NULL, min.bin = 1, .combine = NULL, sigma = 1.5, smooth = FALSE, type = NULL, cols = "turbo", alpha = 0.5, tile.border = NA, layerId = NULL, group = NULL, legend = TRUE, legend.position = "topright", legend.title = NULL, legend.title.autotext = TRUE, ... )addTrajLevel( map, data = leaflet::getMapData(map), lng = "lon", lat = "lat", pollutant = NULL, statistic = "frequency", percentile = 90, lon.inc = 1, lat.inc = 1, breaks = NULL, min.bin = 1, .combine = NULL, sigma = 1.5, smooth = FALSE, type = NULL, cols = "turbo", alpha = 0.5, tile.border = NA, layerId = NULL, group = NULL, legend = TRUE, legend.position = "topright", legend.title = NULL, legend.title.autotext = TRUE, ... )
map |
a map widget object created from |
data |
Data frame, the result of importing a trajectory file using
|
lng |
The decimal longitude. |
lat |
The decimal latitude. |
pollutant |
The pollutant of interest. Not required when |
statistic |
One of:
|
percentile |
The percentile concentration of |
lon.inc, lat.inc
|
The longitude and latitude intervals to be used for
binning data. If |
breaks |
|
min.bin |
The minimum number of unique points in a grid cell. Counts
below |
.combine |
When statistic is "SQTBA" it is possible to combine lots of
receptor locations to derive a single map. |
sigma |
For the SQTBA approach |
smooth |
Should the trajectory surface be smoothed? Defaults to |
type |
Optionally, a method to condition the |
cols |
The colours used for plotting, passed to
|
alpha |
Opacity of the tiles. Must be between |
tile.border |
Colour to use for the border of binned tiles. Defaults to
|
layerId |
The base string for the layer id. The actual layer IDs will be in the format "layerId-tilenum". For example, the first tile will be "layerId-1". |
group |
the name of the group the newly created layers should belong to
(for |
legend |
Should a legend be added to the map? Defaults to |
legend.position |
Where should the legend be placed? One of "topright",
"topleft", "bottomleft" or "bottomright". Passed to the |
legend.title |
Title of the legend. By default, when |
legend.title.autotext |
When |
... |
Other arguments to pass to |
A leaflet object.
## Not run: library(leaflet) leaflet() |> addTiles() |> addTrajLevel( data = traj_data, pollutant = "pm2.5", statistic = "pscf", min.bin = 10, group = "PSCF" ) |> addLayersControl(overlayGroups = "PSCF") ## End(Not run)## Not run: library(leaflet) leaflet() |> addTiles() |> addTrajLevel( data = traj_data, pollutant = "pm2.5", statistic = "pscf", min.bin = 10, group = "PSCF" ) |> addLayersControl(overlayGroups = "PSCF") ## End(Not run)
This function is similar (but not identical to) the leaflet::addMarkers()
function in leaflet, which allows users to add trajectory paths to any
leaflet map and have more control over groups and layerIds than in
"all-in-one" functions like trajMap().
addTrajPaths( map, lng = "lon", lat = "lat", layerId = NULL, group = NULL, data = leaflet::getMapData(map), npoints = 12, markerColor = NULL, ... )addTrajPaths( map, lng = "lon", lat = "lat", layerId = NULL, group = NULL, data = leaflet::getMapData(map), npoints = 12, markerColor = NULL, ... )
map |
a map widget object created from |
lng |
The decimal longitude. |
lat |
The decimal latitude. |
layerId |
The base string for the layer id. The actual layer IDs will be in the format "layerId-linenum" for lines and "layerId_linenum-pointnum" for points. For example, the first point of the first trajectory path will be "layerId-1-1". |
group |
the name of the group the newly created layers should belong to
(for |
data |
Data frame, the result of importing a trajectory file using
|
npoints |
A dot is placed every |
markerColor |
An optional colour (or vector of colours, one per row of
|
... |
Other arguments o pass to both |
addTrajPaths() can be a powerful way of quickly plotting
trajectories on a leaflet map, but users should take some care due to any
additional arguments being passed to both leaflet::addCircleMarkers() and
leaflet::addPolylines(). In particular, users should be weary of the use
of the color argument. Specifically, if color is passed a vector of
length greater than one, multiple polylines will be drawn on top of one
another. At best this will affect opacity, but at worst this will
significantly impact the performance of R and the final leaflet map.
To mitigate this, please ensure that any vector passed to color is of
length one. This is simple if you want the whole path to be the same
colour, but more difficult if you want to colour by a pollutant, for
example. The easiest way to achieve this is to write a for loop or use
another iterative approach (e.g. the purrr package) to add one path per
arrival date. An example of this is provided in the Examples.
If you only need to vary the colour of the markers rather than the
lines - for example, colouring the points by a pollutant that changes
over time - use markerColor instead, which is not subject to the same
length-one restriction as color and can vary across every trajectory
in data, not just within one. This often avoids the need for a loop
entirely; see the Examples.
A leaflet object.
shiny::runExample(package = "openairmaps") to see examples of this
function used in a shiny::shinyApp()
## Not run: library(leaflet) pal <- colorNumeric(palette = "viridis", domain = traj_data$height) map <- leaflet() |> addTiles() for (i in seq_along(unique(traj_data$date))) { data <- dplyr::filter(traj_data, date == unique(traj_data$date)[i]) map <- map |> addTrajPaths( data = data, color = pal(data$height)[1], markerColor = pal(data$height), opacity = 0.5, fillOpacity = 0.8 ) } map ## End(Not run)## Not run: library(leaflet) pal <- colorNumeric(palette = "viridis", domain = traj_data$height) map <- leaflet() |> addTiles() for (i in seq_along(unique(traj_data$date))) { data <- dplyr::filter(traj_data, date == unique(traj_data$date)[i]) map <- map |> addTrajPaths( data = data, color = pal(data$height)[1], markerColor = pal(data$height), opacity = 0.5, fillOpacity = 0.8 ) } map ## End(Not run)
The annulusMap() function creates a map using polar annulus plots as
markers. Any number of pollutants can be specified using the pollutant
argument, and multiple layers of markers can be created using type. By
default, these maps are dynamic and can be panned, zoomed, and otherwise
interacted with. Using the static argument allows for static images to be
produced instead.
annulusMap( data, pollutant = NULL, period = "hour", limits = "free", breaks = NULL, latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )annulusMap( data, pollutant = NULL, period = "hour", limits = "free", breaks = NULL, latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )
data |
Input data table with pollutant, wind, and geo-spatial information. required | scope: dynamic & static A data frame. The data frame must contain the data to plot the directional
analysis marker, which includes wind speed ( |
pollutant |
Pollutant name(s). required | scope: dynamic & static The column name(s) of the pollutant(s) to plot. If multiple pollutants are
specified and a non-pairwise statistic is supplied, the
Multiple |
period |
Temporal period for radial axis. default: Options are "hour" (the default, to plot diurnal variations), "season" to plot variation throughout the year, "weekday" to plot day of the week variation and "trend" to plot the trend by wind direction. |
limits |
Specifier for the plot colour scale bounds. default: One of:
|
breaks |
Specifier for a binned colour scale. default: By default, markers use a continuous colour scale (see
In all cases, a single set of breakpoints is calculated across all of the
markers, so that they share the same intervals and a shared legend can be
drawn. If any of the markers' data fall outside of the given breakpoints,
the lowest and/or highest breakpoints are extended to cover them. If
|
latitude, longitude
|
The decimal latitude(Y)/longitude(X). default: Column names representing the decimal latitude and longitude (or other Y/X
coordinate if using a different |
crs |
The coordinate reference system (CRS). default: The coordinate reference system (CRS) of the data, passed to
|
type |
A method to condition the default: Used for splitting the input data into different groups, passed to the
|
popup |
Content for marker popups on dynamic maps. default: Columns to be used as the HTML content for marker popups on dynamic maps.
Popups may be useful to show information about the individual sites (e.g.,
site names, codes, types, etc.). If a vector of column names are provided
they are passed to Numeric columns (e.g., pollutant concentrations) have many values at each
marker, so are averaged and labelled as such (e.g., "NO2
(mean)"). Names given to |
label |
Content for marker hover-over on dynamic maps. default: Column to be used as the HTML content for hover-over labels. Labels are
useful for the same reasons as popups, though are typically shorter. As
with |
provider |
The basemap(s) to be used. default: The base map(s) to be used for the map. If not provided, will default to
There is some overlap in static and dynamic providers. For example,
|
cols |
Colours to use for plotting. default: The colours used for plotting, passed to |
alpha |
Transparency value for polar markers. default: A value between 0 (fully transparent) and 1 (fully opaque). |
theme |
Custom ggplot2 theme for the polar markers. default: A custom |
key.position |
Legend position for individual marker legends. default: When |
legend |
Draw a shared legend? default: When all markers share the same colour scale, should a shared legend be created at the side of the map? This is the case for:
|
legend.position |
Position of the shared legend. default: When
|
legend.title |
Title of the legend. default: By default, when |
legend.title.autotext |
Automatically format the title of the legend? default: When |
control.collapsed |
Show the layer control as a collapsed? default: For dynamic maps, should the "layer control" interface be collapsed? If
|
control.position |
Position of the layer control menu default: When |
control.autotext |
Automatically format the content of the layer control menu? default: When |
d.icon |
The diameter of the plot on the map in pixels. default: This will affect the size of the individual polar markers. Alternatively, a
vector in the form |
d.fig |
The diameter of the plots to be produced using default: This will affect the resolution of the markers on the map. Alternatively, a
vector in the form |
static |
Produce a static map? default: This controls whether a dynamic or static map is produced. The former is the default and is broadly more useful, but the latter may be preferable for DOCX or PDF outputs (e.g., academic papers). |
static.nrow |
Number of rows in a static map. default: Controls the number of rows of panels on a static map when multiple
|
api_key |
API key for certain 'static' base map providers. default: Passed to the |
progress |
Show a progress bar? default: By default, a progress bar is shown to visualise the function's progress creating individual polar markers. This option allows this to be turned off, if desired. |
... |
Arguments passed on to
|
control |
Removed. Please use |
Either:
Dynamic: A leaflet object
Static: A ggplot2 object using ggplot2::coord_sf() coordinates with a ggspatial basemap
Creating a directional analysis map can take a lot of time; each polar
marker needs to be plot individually, and many of these require some
expensive computations. openairmaps supports parallel processing with
{mirai} to speed these computations up. Users may create workers by
running mirai::daemons() in their R session.
mirai::daemons(4) polarMap(polar_data, "no2")
Typically, spawning one fewer daemons than your number of available cores
is a useful rule of thumb. Parallel processing will be most useful for the
most computationally intensive plotting functions - i.e., polarMap() and
annulusMap().
As all static plots functions are ggplot2 figures, further customisation
is possible using functions such as ggplot2::theme(), ggplot2::guides()
and ggplot2::labs().
Subscripting pollutants (e.g., the "x" in "NOx") is achieved using the
ggtext package. Therefore if you choose to override the
plot theme, it is recommended to use [ggplot2::theme()] and
[ggtext::element_markdown()] to define the strip.text parameter.
Legends can be removed using ggplot2::theme(legend.position = "none"), or
further customised using ggplot2::guides() and either color = ggplot2::guide_colourbar() for continuous legends or color = ggplot2::guide_legend() for discrete legends.
The extent of a map can be adjusted using the xlim and ylim arguments
of ggplot2::coord_sf().
polarMap(polar_data, "no2", static = TRUE) +
ggplot2::coord_sf(
xlim = c(-0.3, 0.2),
ylim = c(51.2, 51.8)
)
Other directional analysis maps:
diffMap(),
freqMap(),
percentileMap(),
polarMap(),
pollroseMap(),
windroseMap()
## Not run: annulusMap(polar_data, pollutant = "nox", period = "hour", provider = "Esri.WorldGrayCanvas" ) ## End(Not run)## Not run: annulusMap(polar_data, pollutant = "nox", period = "hour", provider = "Esri.WorldGrayCanvas" ) ## End(Not run)
Group a dataframe together by latitude/longitude columns and create a HTML
popup with user-defined columns. By default, the unique values of character
columns are collapsed into comma-separated lists, numeric columns are
averaged, and date columns are presented as a range. This function returns
the input dataframe appended with a "popup" column, which can then be used in
the popup argument of a function like polarMap().
buildPopup( data, columns, latitude = NULL, longitude = NULL, type = NULL, fun.character = function(x) { paste(unique(x), collapse = ", ") }, fun.numeric = function(x) { signif(mean(x, na.rm = TRUE), 3) }, fun.dttm = function(x) { paste(lubridate::floor_date(range(x, na.rm = TRUE), "day"), collapse = " to ") }, name = "popup", ... )buildPopup( data, columns, latitude = NULL, longitude = NULL, type = NULL, fun.character = function(x) { paste(unique(x), collapse = ", ") }, fun.numeric = function(x) { signif(mean(x, na.rm = TRUE), 3) }, fun.dttm = function(x) { paste(lubridate::floor_date(range(x, na.rm = TRUE), "day"), collapse = " to ") }, name = "popup", ... )
data |
Input data table with geo-spatial information. required A data frame containing latitude and longitude information that will go on
to be used in a function such as |
columns |
A character vector of column names to include in the popup. required Summaries of the selected columns will appear in the popup. If a named vector is provided, the names of the vector will be used in place of the raw column names. See the Examples for more information. |
latitude, longitude
|
The decimal latitude(Y)/longitude(X). default: Column names representing the decimal latitude and longitude (or other Y/X
coordinate if using a different |
type |
A column to be passed to the default: Column which will be used for the |
fun.character |
A function to summarise character, factor and logical columns. default: The default collapses unique values into a comma-separated list. |
fun.numeric |
A function to summarise numeric columns. default: The default takes the mean to three significant figures. Other numeric summaries may be of interest, such as the maximum, minimum, standard deviation, and so on. |
fun.dttm |
A function to summarise date and date-time columns. default: The default presents the date as a range. Other statistics of interest could be the start or end of the dates. |
name |
The name for the new column. default: A character string for the name for the new column to be appended to
|
... |
Not currently used. |
a tibble
## Not run: buildPopup( data = polar_data, columns = c( "Site" = "site", "Site Type" = "site_type", "Date Range" = "date" ) ) |> polarMap("nox", popup = "popup") ## End(Not run)## Not run: buildPopup( data = polar_data, columns = c( "Site" = "site", "Site Type" = "site_type", "Date Range" = "date" ) ) |> polarMap("nox", popup = "popup") ## End(Not run)
This is a much simpler implementation of the tools found in the
PostcodesioR R package, intended for use with the networkMap()
function.
convertPostcode(postcode)convertPostcode(postcode)
postcode |
A valid UK postcode. required A string containing a single valid UK postcode, e.g., |
A list containing the latitude, longitude, and input postcode.
The PostcodesioR package at
https://github.com/ropensci/PostcodesioR/
# convert a UK postcode convertPostcode("SW1A1AA") ## Not run: # use with `networkMap()` palace <- convertPostcode("SW1A1AA") networkMap("aurn", lat = palace$lat, lng = palace$lng, max_dist = 10) ## End(Not run)# convert a UK postcode convertPostcode("SW1A1AA") ## Not run: # use with `networkMap()` palace <- convertPostcode("SW1A1AA") networkMap("aurn", lat = palace$lat, lng = palace$lng, max_dist = 10) ## End(Not run)
The diffMap() function creates a map using bivariate polar plots as
markers. Any number of pollutants can be specified using the pollutant
argument, and multiple layers of markers can be created using type. By
default, these maps are dynamic and can be panned, zoomed, and otherwise
interacted with. Using the static argument allows for static images to be
produced instead.
diffMap( before, after, pollutant = NULL, x = "ws", limits = "free", latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = rev(openair::openColours("RdBu", 10)), alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )diffMap( before, after, pollutant = NULL, x = "ws", limits = "free", latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = rev(openair::openColours("RdBu", 10)), alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )
before, after
|
Data frames representing the "before" and "after" cases.
See |
pollutant |
Mandatory. A pollutant name corresponding to a variable in a
data frame should be supplied e.g. |
x |
Name of variable to plot against wind direction in polar coordinates, the default is wind speed, “ws”. |
limits |
Limits for the plot colour scale. default: One of:
Note that the |
latitude, longitude
|
The decimal latitude(Y)/longitude(X). default: Column names representing the decimal latitude and longitude (or other Y/X
coordinate if using a different |
crs |
The coordinate reference system (CRS). default: The coordinate reference system (CRS) of the data, passed to
|
type |
Character string(s) defining how data should be split/conditioned
before plotting.
Most |
popup |
Content for marker popups on dynamic maps. default: Columns to be used as the HTML content for marker popups on dynamic maps.
Popups may be useful to show information about the individual sites (e.g.,
site names, codes, types, etc.). If a vector of column names are provided
they are passed to Numeric columns (e.g., pollutant concentrations) have many values at each
marker, so are averaged and labelled as such (e.g., "NO2
(mean)"). Names given to |
label |
Content for marker hover-over on dynamic maps. default: Column to be used as the HTML content for hover-over labels. Labels are
useful for the same reasons as popups, though are typically shorter. As
with |
provider |
The basemap(s) to be used. default: The base map(s) to be used for the map. If not provided, will default to
There is some overlap in static and dynamic providers. For example,
|
cols |
Colours to use for plotting. default: The colours used for plotting, passed to |
alpha |
Transparency value for polar markers. default: A value between 0 (fully transparent) and 1 (fully opaque). |
theme |
Custom ggplot2 theme for the polar markers. default: A custom |
key.position |
Legend position for individual marker legends. default: When |
legend |
Draw a shared legend? default: When all markers share the same colour scale, should a shared legend be created at the side of the map? This is the case for:
|
legend.position |
Position of the shared legend. default: When
|
legend.title |
Title of the legend. default: By default, when |
legend.title.autotext |
Automatically format the title of the legend? default: When |
control.collapsed |
Show the layer control as a collapsed? default: For dynamic maps, should the "layer control" interface be collapsed? If
|
control.position |
Position of the layer control menu default: When |
control.autotext |
Automatically format the content of the layer control menu? default: When |
d.icon |
The diameter of the plot on the map in pixels. default: This will affect the size of the individual polar markers. Alternatively, a
vector in the form |
d.fig |
The diameter of the plots to be produced using default: This will affect the resolution of the markers on the map. Alternatively, a
vector in the form |
static |
Produce a static map? default: This controls whether a dynamic or static map is produced. The former is the default and is broadly more useful, but the latter may be preferable for DOCX or PDF outputs (e.g., academic papers). |
static.nrow |
Number of rows in a static map. default: Controls the number of rows of panels on a static map when multiple
|
api_key |
API key for certain 'static' base map providers. default: Passed to the |
progress |
Show a progress bar? default: By default, a progress bar is shown to visualise the function's progress creating individual polar markers. This option allows this to be turned off, if desired. |
... |
Arguments passed on to
|
control |
Removed. Please use |
Either:
Dynamic: A leaflet object
Static: A ggplot2 object using ggplot2::coord_sf() coordinates with a ggspatial basemap
Creating a directional analysis map can take a lot of time; each polar
marker needs to be plot individually, and many of these require some
expensive computations. openairmaps supports parallel processing with
{mirai} to speed these computations up. Users may create workers by
running mirai::daemons() in their R session.
mirai::daemons(4) polarMap(polar_data, "no2")
Typically, spawning one fewer daemons than your number of available cores
is a useful rule of thumb. Parallel processing will be most useful for the
most computationally intensive plotting functions - i.e., polarMap() and
annulusMap().
As all static plots functions are ggplot2 figures, further customisation
is possible using functions such as ggplot2::theme(), ggplot2::guides()
and ggplot2::labs().
Subscripting pollutants (e.g., the "x" in "NOx") is achieved using the
ggtext package. Therefore if you choose to override the
plot theme, it is recommended to use [ggplot2::theme()] and
[ggtext::element_markdown()] to define the strip.text parameter.
Legends can be removed using ggplot2::theme(legend.position = "none"), or
further customised using ggplot2::guides() and either color = ggplot2::guide_colourbar() for continuous legends or color = ggplot2::guide_legend() for discrete legends.
The extent of a map can be adjusted using the xlim and ylim arguments
of ggplot2::coord_sf().
polarMap(polar_data, "no2", static = TRUE) +
ggplot2::coord_sf(
xlim = c(-0.3, 0.2),
ylim = c(51.2, 51.8)
)
Other directional analysis maps:
annulusMap(),
freqMap(),
percentileMap(),
polarMap(),
pollroseMap(),
windroseMap()
## Not run: # NB: "after" is some dummy data to demonstrate functionality diffMap( before = polar_data, after = dplyr::mutate(polar_data, nox = jitter(nox, factor = 5)), pollutant = "nox" ) ## End(Not run)## Not run: # NB: "after" is some dummy data to demonstrate functionality diffMap( before = polar_data, after = dplyr::mutate(polar_data, nox = jitter(nox, factor = 5)), pollutant = "nox" ) ## End(Not run)
The freqMap() function creates a map using polar frequency plots as
markers. Any number of pollutants can be specified using the pollutant
argument, and multiple layers of markers can be created using type. By
default, these maps are dynamic and can be panned, zoomed, and otherwise
interacted with. Using the static argument allows for static images to be
produced instead.
freqMap( data, pollutant = NULL, statistic = "mean", breaks = "free", latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )freqMap( data, pollutant = NULL, statistic = "mean", breaks = "free", latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )
data |
Input data table with pollutant, wind, and geo-spatial information. required | scope: dynamic & static A data frame. The data frame must contain the data to plot the directional
analysis marker, which includes wind speed ( |
pollutant |
Pollutant name(s). required | scope: dynamic & static The column name(s) of the pollutant(s) to plot. If multiple pollutants are
specified and a non-pairwise statistic is supplied, the
Multiple |
statistic |
The statistic that should be applied to each wind speed/direction bin. default: Can be "frequency", "mean", "median", "max" (maximum), "stdev" (standard
deviation) or "weighted.mean". The option "frequency" is the simplest and
plots the frequency of wind speed/direction in different bins. The scale
therefore shows the counts in each bin. The option "mean" (the default) will
plot the mean concentration of a pollutant (see next point) in wind
speed/direction bins, and so on. Finally, "weighted.mean" will plot the
concentration of a pollutant weighted by wind speed/direction. Each segment
therefore provides the percentage overall contribution to the total
concentration. Note that for options other than "frequency", it is necessary
to also provide the name of a pollutant. See function |
breaks |
Specifier for the breaks of the plot colour scale. default: One of:
|
latitude, longitude
|
The decimal latitude(Y)/longitude(X). default: Column names representing the decimal latitude and longitude (or other Y/X
coordinate if using a different |
crs |
The coordinate reference system (CRS). default: The coordinate reference system (CRS) of the data, passed to
|
type |
A method to condition the default: Used for splitting the input data into different groups, passed to the
|
popup |
Content for marker popups on dynamic maps. default: Columns to be used as the HTML content for marker popups on dynamic maps.
Popups may be useful to show information about the individual sites (e.g.,
site names, codes, types, etc.). If a vector of column names are provided
they are passed to Numeric columns (e.g., pollutant concentrations) have many values at each
marker, so are averaged and labelled as such (e.g., "NO2
(mean)"). Names given to |
label |
Content for marker hover-over on dynamic maps. default: Column to be used as the HTML content for hover-over labels. Labels are
useful for the same reasons as popups, though are typically shorter. As
with |
provider |
The basemap(s) to be used. default: The base map(s) to be used for the map. If not provided, will default to
There is some overlap in static and dynamic providers. For example,
|
cols |
Colours to use for plotting. default: The colours used for plotting, passed to |
alpha |
Transparency value for polar markers. default: A value between 0 (fully transparent) and 1 (fully opaque). |
theme |
Custom ggplot2 theme for the polar markers. default: A custom |
key.position |
Legend position for individual marker legends. default: When |
legend |
Draw a shared legend? default: When all markers share the same colour scale, should a shared legend be created at the side of the map? This is the case for:
|
legend.position |
Position of the shared legend. default: When
|
legend.title |
Title of the legend. default: By default, when |
legend.title.autotext |
Automatically format the title of the legend? default: When |
control.collapsed |
Show the layer control as a collapsed? default: For dynamic maps, should the "layer control" interface be collapsed? If
|
control.position |
Position of the layer control menu default: When |
control.autotext |
Automatically format the content of the layer control menu? default: When |
d.icon |
The diameter of the plot on the map in pixels. default: This will affect the size of the individual polar markers. Alternatively, a
vector in the form |
d.fig |
The diameter of the plots to be produced using default: This will affect the resolution of the markers on the map. Alternatively, a
vector in the form |
static |
Produce a static map? default: This controls whether a dynamic or static map is produced. The former is the default and is broadly more useful, but the latter may be preferable for DOCX or PDF outputs (e.g., academic papers). |
static.nrow |
Number of rows in a static map. default: Controls the number of rows of panels on a static map when multiple
|
api_key |
API key for certain 'static' base map providers. default: Passed to the |
progress |
Show a progress bar? default: By default, a progress bar is shown to visualise the function's progress creating individual polar markers. This option allows this to be turned off, if desired. |
... |
Arguments passed on to
|
control |
Removed. Please use |
Either:
Dynamic: A leaflet object
Static: A ggplot2 object using ggplot2::coord_sf() coordinates with a ggspatial basemap
Creating a directional analysis map can take a lot of time; each polar
marker needs to be plot individually, and many of these require some
expensive computations. openairmaps supports parallel processing with
{mirai} to speed these computations up. Users may create workers by
running mirai::daemons() in their R session.
mirai::daemons(4) polarMap(polar_data, "no2")
Typically, spawning one fewer daemons than your number of available cores
is a useful rule of thumb. Parallel processing will be most useful for the
most computationally intensive plotting functions - i.e., polarMap() and
annulusMap().
As all static plots functions are ggplot2 figures, further customisation
is possible using functions such as ggplot2::theme(), ggplot2::guides()
and ggplot2::labs().
Subscripting pollutants (e.g., the "x" in "NOx") is achieved using the
ggtext package. Therefore if you choose to override the
plot theme, it is recommended to use [ggplot2::theme()] and
[ggtext::element_markdown()] to define the strip.text parameter.
Legends can be removed using ggplot2::theme(legend.position = "none"), or
further customised using ggplot2::guides() and either color = ggplot2::guide_colourbar() for continuous legends or color = ggplot2::guide_legend() for discrete legends.
The extent of a map can be adjusted using the xlim and ylim arguments
of ggplot2::coord_sf().
polarMap(polar_data, "no2", static = TRUE) +
ggplot2::coord_sf(
xlim = c(-0.3, 0.2),
ylim = c(51.2, 51.8)
)
Other directional analysis maps:
annulusMap(),
diffMap(),
percentileMap(),
polarMap(),
pollroseMap(),
windroseMap()
## Not run: freqMap(polar_data, pollutant = "nox", statistic = "mean", provider = "Esri.WorldGrayCanvas" ) ## End(Not run)## Not run: freqMap(polar_data, pollutant = "nox", statistic = "mean", provider = "Esri.WorldGrayCanvas" ) ## End(Not run)
These functions create interpolated surfaces out of data at individual
monitoring sites. This can be useful to 'fill in the gaps' to estimate
pollution concentrations where no monitoring is occurring, or better
identify geographical patterns in pollution data. krigingMap() creates a
smooth spatially interpolated surface using either inverse distance
weighting or point kriging. voronoiMap() creates a surface of 'closest
observation' polygons. The kriging formula is currently always pollutant ~ 1; krigingMap() does not currently support more complex models.
When type is used, each type level is summarised and interpolated
separately, but all levels share the same colour scale so that they can
be compared.
krigingMap( data, pollutant = NULL, statistic = "mean", percentile = 95, newdata = NULL, method = c("idw", "kriging"), breaks = NULL, labels = NULL, limits = NULL, latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 0.8, show.markers = TRUE, marker.border = "white", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, static = FALSE, static.nrow = NULL, api_key = NULL, vgm = gstat::vgm(psill = 1, model = "Exp", range = 50, nugget = 1), args.idw = list(debug.level = 0), args.variogram = list(), args.fit.variogram = list(), args.krige = list(debug.level = 0), ... ) voronoiMap( data, pollutant = NULL, statistic = "mean", percentile = 95, newdata = NULL, breaks = NULL, labels = NULL, limits = NULL, latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 0.8, show.markers = TRUE, marker.border = "white", voronoi.border = "white", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, static = FALSE, static.nrow = NULL, api_key = NULL, args.voronoi = list(), ... )krigingMap( data, pollutant = NULL, statistic = "mean", percentile = 95, newdata = NULL, method = c("idw", "kriging"), breaks = NULL, labels = NULL, limits = NULL, latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 0.8, show.markers = TRUE, marker.border = "white", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, static = FALSE, static.nrow = NULL, api_key = NULL, vgm = gstat::vgm(psill = 1, model = "Exp", range = 50, nugget = 1), args.idw = list(debug.level = 0), args.variogram = list(), args.fit.variogram = list(), args.krige = list(debug.level = 0), ... ) voronoiMap( data, pollutant = NULL, statistic = "mean", percentile = 95, newdata = NULL, breaks = NULL, labels = NULL, limits = NULL, latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 0.8, show.markers = TRUE, marker.border = "white", voronoi.border = "white", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, static = FALSE, static.nrow = NULL, api_key = NULL, args.voronoi = list(), ... )
data |
Input data table with pollutant and geo-spatial information. required | scope: dynamic & static A data frame. The data frame must contain at least one numeric column to
interpolate, plus a decimal latitude and longitude (or X/Y coordinate used
in conjunction with |
pollutant |
Pollutant name. required | scope: dynamic & static The column name of the pollutant to plot. Multiple |
statistic |
Statistic for aggregating pollutant data. default: Pollutant data will be aggregated by latitude & longitude;
To show this value in marker popups or labels, include |
percentile |
The percentile when 'statistic = "percentile" default: The percentile level used when |
newdata |
A spatial dataset of prediction locations. default: By default, a bounding box of all latitudes and longitudes are used for
prediction, but this is often not useful or aesthetically pleasing.
|
method |
Spatial interpolation method. default: The spatial interpolation method to use for |
labels, breaks
|
Discretise the map color scale. default: By default, a continuous colour scale is used. If If the data extend beyond |
limits |
Specifier for the plot colour scale bounds. default: A numeric vector in the form |
latitude, longitude
|
The decimal latitude(Y)/longitude(X). default: Column names representing the decimal latitude and longitude (or other Y/X
coordinate if using a different |
crs |
The coordinate reference system (CRS). default: The coordinate reference system (CRS) of the data, passed to
|
type |
A method to condition the default: Used for splitting the input data into different groups, passed to the
|
popup |
Content for marker popups on dynamic maps. default: Columns to be used as the HTML content for site marker popups on dynamic
maps. Popups may be useful to show information about the individual sites
(e.g., site names, codes, types, etc.). If a vector of column names are
provided they are passed to The |
label |
Content for marker hover-over on dynamic maps. default: Column to be used as the HTML content for hover-over labels. Labels are
useful for the same reasons as popups, though are typically shorter. The
|
provider |
The basemap(s) to be used. default: The base map(s) to be used for the map. If not provided, will default to
There is some overlap in static and dynamic providers. For example,
|
cols |
Colours to use for plotting. default: The colours used for plotting, passed to |
alpha |
Transparency value for interpolated surface. default: A value between 0 (fully transparent) and 1 (fully opaque). |
show.markers |
Show original monitoring site markers? default: When |
marker.border, voronoi.border
|
Border colour to use for markers and voronoi tiles. default: Any valid HTML colour (e.g., a hex code). Use |
legend |
Draw a legend? default: When |
legend.position |
Position of the shared legend. default: When
|
legend.title |
Title of the legend. default: By default, when |
legend.title.autotext |
Automatically format the title of the legend? default: When |
control.collapsed |
Show the layer control as a collapsed? default: For dynamic maps, should the "layer control" interface be collapsed? If
|
control.position |
Position of the layer control menu default: When |
control.autotext |
Automatically format the content of the layer control menu? default: When |
static |
Produce a static map? default: This controls whether a dynamic or static map is produced. The former is the default and is broadly more useful, but the latter may be preferable for DOCX or PDF outputs (e.g., academic papers). |
static.nrow |
Number of rows in a static map. default: Controls the number of rows of panels on a static map when multiple
|
api_key |
API key for certain 'static' base map providers. default: Passed to the |
vgm |
A variogram model default: The variogram model to use when |
args.idw, args.variogram, args.fit.variogram, args.krige
|
Extra arguments
to pass to spatial interpolation functions for scope: dynamic & static Extra arguments passed to |
... |
Arguments passed on to
|
args.voronoi |
Extra arguments to pass to spatial interpolation
functions for scope: dynamic & static Extra arguments passed to |
Either:
Dynamic: A leaflet object
Static: A ggplot2 object using ggplot2::coord_sf() coordinates with a ggspatial basemap
As all static plots functions are ggplot2 figures, further customisation
is possible using functions such as ggplot2::theme(), ggplot2::guides()
and ggplot2::labs().
Subscripting pollutants (e.g., the "x" in "NOx") is achieved using the
ggtext package. Therefore if you choose to override the
plot theme, it is recommended to use [ggplot2::theme()] and
[ggtext::element_markdown()] to define the strip.text parameter.
Legends can be removed using ggplot2::theme(legend.position = "none"), or
further customised using ggplot2::guides() and either color = ggplot2::guide_colourbar() for continuous legends or color = ggplot2::guide_legend() for discrete legends.
The extent of a map can be adjusted using the xlim and ylim arguments
of ggplot2::coord_sf().
polarMap(polar_data, "no2", static = TRUE) +
ggplot2::coord_sf(
xlim = c(-0.3, 0.2),
ylim = c(51.2, 51.8)
)
## Not run: # import ozone DAQI daqi <- openair::importUKAQ( pollutant = "o3", year = 2020, source = "aurn", data_type = "daqi", meta = TRUE ) # get a UK shapefile uk <- rnaturalearth::ne_countries(scale = 10, country = "united kingdom") # create spatially interpolated map voronoiMap( daqi, pollutant = "poll_index", newdata = uk, statistic = "max", breaks = seq(0.5, 10.5, 1), labels = as.character(1:10), legend.title = "Max O3 DAQI", cols = "daqi" ) krigingMap( daqi, pollutant = "poll_index", newdata = uk, statistic = "max", legend.title = "Max O3 DAQI", cols = openair::openColours("daqi", n = 10), limits = c(1, 10) ) ## End(Not run)## Not run: # import ozone DAQI daqi <- openair::importUKAQ( pollutant = "o3", year = 2020, source = "aurn", data_type = "daqi", meta = TRUE ) # get a UK shapefile uk <- rnaturalearth::ne_countries(scale = 10, country = "united kingdom") # create spatially interpolated map voronoiMap( daqi, pollutant = "poll_index", newdata = uk, statistic = "max", breaks = seq(0.5, 10.5, 1), labels = as.character(1:10), legend.title = "Max O3 DAQI", cols = "daqi" ) krigingMap( daqi, pollutant = "poll_index", newdata = uk, statistic = "max", legend.title = "Max O3 DAQI", cols = openair::openColours("daqi", n = 10), limits = c(1, 10) ) ## End(Not run)
This function uses openair::importMeta() to obtain metadata for measurement
sites and uses it to create an interactive leaflet map. By default a map
will be created in which readers may toggle between a vector base map and a
satellite/aerial image, although users can further customise the control menu
using the provider and control parameters. Any argument which can be
passed to openair::importMeta() can be passed via ..., with the exception
of all and duplicate.
networkMap( source = "aurn", ..., control = NULL, cluster = NULL, provider = c(Default = "OpenStreetMap", Satellite = "Esri.WorldImagery"), legend = TRUE, legend.position = "topright", control.collapsed = FALSE, control.position = "topright" )networkMap( source = "aurn", ..., control = NULL, cluster = NULL, provider = c(Default = "OpenStreetMap", Satellite = "Esri.WorldImagery"), legend = TRUE, legend.position = "topright", control.collapsed = FALSE, control.position = "topright" )
source |
One or more UK or European monitoring networks. default: One or more air quality networks for which data is available through openair. Available networks include:
There are two additional options provided for convenience:
|
... |
Arguments passed on to
|
control |
Option to create a 'layer control' menu. default: A string to specify categories in a "layer control" menu, to allow readers to select between different site categories. Choices include:
|
cluster |
Cluster markers together when zoomed out? default: When |
provider |
The basemap(s) to be used. default: Any number of leaflet::providers. See
http://leaflet-extras.github.io/leaflet-providers/preview/ for a list of
all base maps that can be used. If multiple base maps are provided, they
can be toggled between using a "layer control" interface. By default, the
interface will use the provider names as labels, but users can define their
own using a named vector (e.g., |
legend |
Draw a shared legend? default: When multiple |
legend.position |
Position of the legend default: Where should the shared legend be placed? One of "topleft", "topright",
"bottomleft" or "bottomright". Passed to the |
control.collapsed |
Show the layer control as a collapsed? default: Should the "layer control" interface be collapsed? If |
control.position |
Position of the layer control menu default: Where should the "layer control" interface be placed? One of "topleft",
"topright", "bottomleft" or "bottomright". Passed to the |
A leaflet object.
## Not run: # view one network, grouped by site type networkMap(source = "aurn", control = "site_type") # view multiple networks, grouped by network networkMap(source = c("aurn", "waqn", "saqn"), control = "network") ## End(Not run)## Not run: # view one network, grouped by site type networkMap(source = "aurn", control = "site_type") # view multiple networks, grouped by network networkMap(source = c("aurn", "waqn", "saqn"), control = "network") ## End(Not run)
The percentileMap() function creates a map using polar percentile roses as
markers. Any number of pollutants can be specified using the pollutant
argument, and multiple layers of markers can be created using type. By
default, these maps are dynamic and can be panned, zoomed, and otherwise
interacted with. Using the static argument allows for static images to be
produced instead.
percentileMap( data, pollutant = NULL, percentile = c(25, 50, 75, 90, 95), intervals = "fixed", latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )percentileMap( data, pollutant = NULL, percentile = c(25, 50, 75, 90, 95), intervals = "fixed", latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )
data |
Input data table with pollutant, wind, and geo-spatial information. required | scope: dynamic & static A data frame. The data frame must contain the data to plot the directional
analysis marker, which includes wind speed ( |
pollutant |
Pollutant name(s). required | scope: dynamic & static The column name(s) of the pollutant(s) to plot. If multiple pollutants are
specified and a non-pairwise statistic is supplied, the
Multiple |
percentile |
The percentile values for the colour scale bin. default: The percentile value(s) to plot using |
intervals |
Specifier for the percentile rose radial axis intervals. default: One of:
|
latitude, longitude
|
The decimal latitude(Y)/longitude(X). default: Column names representing the decimal latitude and longitude (or other Y/X
coordinate if using a different |
crs |
The coordinate reference system (CRS). default: The coordinate reference system (CRS) of the data, passed to
|
type |
A method to condition the default: Used for splitting the input data into different groups, passed to the
|
popup |
Content for marker popups on dynamic maps. default: Columns to be used as the HTML content for marker popups on dynamic maps.
Popups may be useful to show information about the individual sites (e.g.,
site names, codes, types, etc.). If a vector of column names are provided
they are passed to Numeric columns (e.g., pollutant concentrations) have many values at each
marker, so are averaged and labelled as such (e.g., "NO2
(mean)"). Names given to |
label |
Content for marker hover-over on dynamic maps. default: Column to be used as the HTML content for hover-over labels. Labels are
useful for the same reasons as popups, though are typically shorter. As
with |
provider |
The basemap(s) to be used. default: The base map(s) to be used for the map. If not provided, will default to
There is some overlap in static and dynamic providers. For example,
|
cols |
Colours to use for plotting. default: The colours used for plotting, passed to |
alpha |
Transparency value for polar markers. default: A value between 0 (fully transparent) and 1 (fully opaque). |
theme |
Custom ggplot2 theme for the polar markers. default: A custom |
key.position |
Legend position for individual marker legends. default: When |
legend |
Draw a shared legend? default: When all markers share the same colour scale, should a shared legend be created at the side of the map? This is the case for:
|
legend.position |
Position of the shared legend. default: When
|
legend.title |
Title of the legend. default: By default, when |
legend.title.autotext |
Automatically format the title of the legend? default: When |
control.collapsed |
Show the layer control as a collapsed? default: For dynamic maps, should the "layer control" interface be collapsed? If
|
control.position |
Position of the layer control menu default: When |
control.autotext |
Automatically format the content of the layer control menu? default: When |
d.icon |
The diameter of the plot on the map in pixels. default: This will affect the size of the individual polar markers. Alternatively, a
vector in the form |
d.fig |
The diameter of the plots to be produced using default: This will affect the resolution of the markers on the map. Alternatively, a
vector in the form |
static |
Produce a static map? default: This controls whether a dynamic or static map is produced. The former is the default and is broadly more useful, but the latter may be preferable for DOCX or PDF outputs (e.g., academic papers). |
static.nrow |
Number of rows in a static map. default: Controls the number of rows of panels on a static map when multiple
|
api_key |
API key for certain 'static' base map providers. default: Passed to the |
progress |
Show a progress bar? default: By default, a progress bar is shown to visualise the function's progress creating individual polar markers. This option allows this to be turned off, if desired. |
... |
Arguments passed on to
|
control |
Removed. Please use |
Either:
Dynamic: A leaflet object
Static: A ggplot2 object using ggplot2::coord_sf() coordinates with a ggspatial basemap
Creating a directional analysis map can take a lot of time; each polar
marker needs to be plot individually, and many of these require some
expensive computations. openairmaps supports parallel processing with
{mirai} to speed these computations up. Users may create workers by
running mirai::daemons() in their R session.
mirai::daemons(4) polarMap(polar_data, "no2")
Typically, spawning one fewer daemons than your number of available cores
is a useful rule of thumb. Parallel processing will be most useful for the
most computationally intensive plotting functions - i.e., polarMap() and
annulusMap().
As all static plots functions are ggplot2 figures, further customisation
is possible using functions such as ggplot2::theme(), ggplot2::guides()
and ggplot2::labs().
Subscripting pollutants (e.g., the "x" in "NOx") is achieved using the
ggtext package. Therefore if you choose to override the
plot theme, it is recommended to use [ggplot2::theme()] and
[ggtext::element_markdown()] to define the strip.text parameter.
Legends can be removed using ggplot2::theme(legend.position = "none"), or
further customised using ggplot2::guides() and either color = ggplot2::guide_colourbar() for continuous legends or color = ggplot2::guide_legend() for discrete legends.
The extent of a map can be adjusted using the xlim and ylim arguments
of ggplot2::coord_sf().
polarMap(polar_data, "no2", static = TRUE) +
ggplot2::coord_sf(
xlim = c(-0.3, 0.2),
ylim = c(51.2, 51.8)
)
Other directional analysis maps:
annulusMap(),
diffMap(),
freqMap(),
polarMap(),
pollroseMap(),
windroseMap()
## Not run: percentileMap(polar_data, pollutant = "nox", provider = "Esri.WorldGrayCanvas" ) ## End(Not run)## Not run: percentileMap(polar_data, pollutant = "nox", provider = "Esri.WorldGrayCanvas" ) ## End(Not run)
pointMap() summarises pollutant data at each monitoring site (e.g., taking
the mean concentration) and shows the result as coloured circles on a map.
It is the simplest way to compare concentrations across a network of sites.
Unlike krigingMap() and voronoiMap(), no attempt is made to estimate
concentrations away from the sites themselves. By default, these maps are
dynamic and can be panned, zoomed, and otherwise interacted with. Using the
static argument allows for static images to be produced instead.
pointMap( data, pollutant = NULL, statistic = "mean", percentile = 95, breaks = NULL, labels = NULL, limits = NULL, latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, marker.border = "white", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, static = FALSE, static.nrow = NULL, api_key = NULL, ... )pointMap( data, pollutant = NULL, statistic = "mean", percentile = 95, breaks = NULL, labels = NULL, limits = NULL, latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, marker.border = "white", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, static = FALSE, static.nrow = NULL, api_key = NULL, ... )
data |
Input data table with pollutant and geo-spatial information. required | scope: dynamic & static A data frame. The data frame must contain at least one numeric column to
interpolate, plus a decimal latitude and longitude (or X/Y coordinate used
in conjunction with |
pollutant |
Pollutant name. required | scope: dynamic & static The column name of the pollutant to plot. Multiple |
statistic |
Statistic for aggregating pollutant data. default: Pollutant data will be aggregated by latitude & longitude;
To show this value in marker popups or labels, include |
percentile |
The percentile when 'statistic = "percentile" default: The percentile level used when |
labels, breaks
|
Discretise the map color scale. default: By default, a continuous colour scale is used. If If the data extend beyond |
limits |
Specifier for the plot colour scale bounds. default: A numeric vector in the form |
latitude, longitude
|
The decimal latitude(Y)/longitude(X). default: Column names representing the decimal latitude and longitude (or other Y/X
coordinate if using a different |
crs |
The coordinate reference system (CRS). default: The coordinate reference system (CRS) of the data, passed to
|
type |
A method to condition the default: Used for splitting the input data into different groups, passed to the
|
popup |
Content for marker popups on dynamic maps. default: Columns to be used as the HTML content for site marker popups on dynamic
maps. Popups may be useful to show information about the individual sites
(e.g., site names, codes, types, etc.). If a vector of column names are
provided they are passed to The |
label |
Content for marker hover-over on dynamic maps. default: Column to be used as the HTML content for hover-over labels. Labels are
useful for the same reasons as popups, though are typically shorter. The
|
provider |
The basemap(s) to be used. default: The base map(s) to be used for the map. If not provided, will default to
There is some overlap in static and dynamic providers. For example,
|
cols |
Colours to use for plotting. default: The colours used for plotting, passed to |
alpha |
Transparency value for the site markers. default: A value between 0 (fully transparent) and 1 (fully opaque). |
marker.border |
Border colour to use for the site markers. default: Any valid HTML colour (e.g., a hex code). Use |
legend |
Draw a legend? default: When |
legend.position |
Position of the shared legend. default: When
|
legend.title |
Title of the legend. default: By default, when |
legend.title.autotext |
Automatically format the title of the legend? default: When |
control.collapsed |
Show the layer control as a collapsed? default: For dynamic maps, should the "layer control" interface be collapsed? If
|
control.position |
Position of the layer control menu default: When |
control.autotext |
Automatically format the content of the layer control menu? default: When |
static |
Produce a static map? default: This controls whether a dynamic or static map is produced. The former is the default and is broadly more useful, but the latter may be preferable for DOCX or PDF outputs (e.g., academic papers). |
static.nrow |
Number of rows in a static map. default: Controls the number of rows of panels on a static map when multiple
|
api_key |
API key for certain 'static' base map providers. default: Passed to the |
... |
Arguments passed on to
|
When type is used, the data are summarised separately for each type
level, but all levels share the same colour scale so that they can be
compared.
Either:
Dynamic: A leaflet object
Static: A ggplot2 object using ggplot2::coord_sf() coordinates with a ggspatial basemap
As all static plots functions are ggplot2 figures, further customisation
is possible using functions such as ggplot2::theme(), ggplot2::guides()
and ggplot2::labs().
Subscripting pollutants (e.g., the "x" in "NOx") is achieved using the
ggtext package. Therefore if you choose to override the
plot theme, it is recommended to use [ggplot2::theme()] and
[ggtext::element_markdown()] to define the strip.text parameter.
Legends can be removed using ggplot2::theme(legend.position = "none"), or
further customised using ggplot2::guides() and either color = ggplot2::guide_colourbar() for continuous legends or color = ggplot2::guide_legend() for discrete legends.
The extent of a map can be adjusted using the xlim and ylim arguments
of ggplot2::coord_sf().
polarMap(polar_data, "no2", static = TRUE) +
ggplot2::coord_sf(
xlim = c(-0.3, 0.2),
ylim = c(51.2, 51.8)
)
krigingMap() and voronoiMap() to spatially interpolate between
the sites.
## Not run: # import ozone DAQI daqi <- openair::importUKAQ( pollutant = "o3", year = 2020, source = "aurn", data_type = "daqi", meta = TRUE ) # maximum DAQI at each site pointMap( daqi, pollutant = "poll_index", statistic = "max", breaks = seq(0.5, 10.5, 1), labels = as.character(1:10), legend.title = "Max O3 DAQI", cols = "daqi" ) ## End(Not run)## Not run: # import ozone DAQI daqi <- openair::importUKAQ( pollutant = "o3", year = 2020, source = "aurn", data_type = "daqi", meta = TRUE ) # maximum DAQI at each site pointMap( daqi, pollutant = "poll_index", statistic = "max", breaks = seq(0.5, 10.5, 1), labels = as.character(1:10), legend.title = "Max O3 DAQI", cols = "daqi" ) ## End(Not run)
The polar_data dataset is provided as an example dataset as part of the
openairmaps package. The dataset contains hourly measurements of air
pollutant concentrations, location and meteorological data.
polar_datapolar_data
An object of class tbl_df (inherits from tbl, data.frame) with 35040 rows and 14 columns.
The site name and code. Useful for use with the popup and label arguments in openairmaps functions.
The date and time of the measurement
Pollutant concentrations
Wind direction, in degrees from North, as a numeric vector.
Wind speed, in m/s, as numeric vector.
The visibility in metres.
Air temperature in degrees Celcius.
Decimal latitude and longitude of the sites.
Site type of the site (either "Urban Traffic" or "Urban Background").
polar_data was compiled from data using the openair::importUKAQ()
function from the openair package with meteorological data from the
worldmet package.
polar_datapolar_data
The polarMap() function creates a map using bivariate polar plots as
markers. Any number of pollutants can be specified using the pollutant
argument, and multiple layers of markers can be created using type. By
default, these maps are dynamic and can be panned, zoomed, and otherwise
interacted with. Using the static argument allows for static images to be
produced instead.
polarMap( data, pollutant = NULL, x = "ws", limits = "free", breaks = NULL, upper = "fixed", latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )polarMap( data, pollutant = NULL, x = "ws", limits = "free", breaks = NULL, upper = "fixed", latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )
data |
Input data table with pollutant, wind, and geo-spatial information. required | scope: dynamic & static A data frame. The data frame must contain the data to plot the directional
analysis marker, which includes wind speed ( |
pollutant |
Pollutant name(s). required | scope: dynamic & static The column name(s) of the pollutant(s) to plot. If multiple pollutants are
specified and a non-pairwise statistic is supplied, the
Multiple |
x |
The radial axis variable. default: The column name for the radial axis variable to use in
|
limits |
Specifier for the plot colour scale bounds. default: One of:
|
breaks |
Specifier for a binned colour scale. default: By default, markers use a continuous colour scale (see
In all cases, a single set of breakpoints is calculated across all of the
markers, so that they share the same intervals and a shared legend can be
drawn. If any of the markers' data fall outside of the given breakpoints,
the lowest and/or highest breakpoints are extended to cover them. If
|
upper |
Specifier for the polar plot radial axis upper boundary. default: One of:
|
latitude, longitude
|
The decimal latitude(Y)/longitude(X). default: Column names representing the decimal latitude and longitude (or other Y/X
coordinate if using a different |
crs |
The coordinate reference system (CRS). default: The coordinate reference system (CRS) of the data, passed to
|
type |
A method to condition the default: Used for splitting the input data into different groups, passed to the
|
popup |
Content for marker popups on dynamic maps. default: Columns to be used as the HTML content for marker popups on dynamic maps.
Popups may be useful to show information about the individual sites (e.g.,
site names, codes, types, etc.). If a vector of column names are provided
they are passed to Numeric columns (e.g., pollutant concentrations) have many values at each
marker, so are averaged and labelled as such (e.g., "NO2
(mean)"). Names given to |
label |
Content for marker hover-over on dynamic maps. default: Column to be used as the HTML content for hover-over labels. Labels are
useful for the same reasons as popups, though are typically shorter. As
with |
provider |
The basemap(s) to be used. default: The base map(s) to be used for the map. If not provided, will default to
There is some overlap in static and dynamic providers. For example,
|
cols |
Colours to use for plotting. default: The colours used for plotting, passed to |
alpha |
Transparency value for polar markers. default: A value between 0 (fully transparent) and 1 (fully opaque). |
theme |
Custom ggplot2 theme for the polar markers. default: A custom |
key.position |
Legend position for individual marker legends. default: When |
legend |
Draw a shared legend? default: When all markers share the same colour scale, should a shared legend be created at the side of the map? This is the case for:
|
legend.position |
Position of the shared legend. default: When
|
legend.title |
Title of the legend. default: By default, when |
legend.title.autotext |
Automatically format the title of the legend? default: When |
control.collapsed |
Show the layer control as a collapsed? default: For dynamic maps, should the "layer control" interface be collapsed? If
|
control.position |
Position of the layer control menu default: When |
control.autotext |
Automatically format the content of the layer control menu? default: When |
d.icon |
The diameter of the plot on the map in pixels. default: This will affect the size of the individual polar markers. Alternatively, a
vector in the form |
d.fig |
The diameter of the plots to be produced using default: This will affect the resolution of the markers on the map. Alternatively, a
vector in the form |
static |
Produce a static map? default: This controls whether a dynamic or static map is produced. The former is the default and is broadly more useful, but the latter may be preferable for DOCX or PDF outputs (e.g., academic papers). |
static.nrow |
Number of rows in a static map. default: Controls the number of rows of panels on a static map when multiple
|
api_key |
API key for certain 'static' base map providers. default: Passed to the |
progress |
Show a progress bar? default: By default, a progress bar is shown to visualise the function's progress creating individual polar markers. This option allows this to be turned off, if desired. |
... |
Arguments passed on to
|
control |
Removed. Please use |
Either:
Dynamic: A leaflet object
Static: A ggplot2 object using ggplot2::coord_sf() coordinates with a ggspatial basemap
Creating a directional analysis map can take a lot of time; each polar
marker needs to be plot individually, and many of these require some
expensive computations. openairmaps supports parallel processing with
{mirai} to speed these computations up. Users may create workers by
running mirai::daemons() in their R session.
mirai::daemons(4) polarMap(polar_data, "no2")
Typically, spawning one fewer daemons than your number of available cores
is a useful rule of thumb. Parallel processing will be most useful for the
most computationally intensive plotting functions - i.e., polarMap() and
annulusMap().
As all static plots functions are ggplot2 figures, further customisation
is possible using functions such as ggplot2::theme(), ggplot2::guides()
and ggplot2::labs().
Subscripting pollutants (e.g., the "x" in "NOx") is achieved using the
ggtext package. Therefore if you choose to override the
plot theme, it is recommended to use [ggplot2::theme()] and
[ggtext::element_markdown()] to define the strip.text parameter.
Legends can be removed using ggplot2::theme(legend.position = "none"), or
further customised using ggplot2::guides() and either color = ggplot2::guide_colourbar() for continuous legends or color = ggplot2::guide_legend() for discrete legends.
The extent of a map can be adjusted using the xlim and ylim arguments
of ggplot2::coord_sf().
polarMap(polar_data, "no2", static = TRUE) +
ggplot2::coord_sf(
xlim = c(-0.3, 0.2),
ylim = c(51.2, 51.8)
)
Other directional analysis maps:
annulusMap(),
diffMap(),
freqMap(),
percentileMap(),
pollroseMap(),
windroseMap()
## Not run: polarMap(polar_data, pollutant = "nox", x = "ws", provider = "Esri.WorldGrayCanvas" ) ## End(Not run)## Not run: polarMap(polar_data, pollutant = "nox", x = "ws", provider = "Esri.WorldGrayCanvas" ) ## End(Not run)
The pollroseMap() function creates a map using pollution roses as markers.
Any number of pollutants can be specified using the pollutant argument, and
multiple layers of markers can be created using type. By default, these
maps are dynamic and can be panned, zoomed, and otherwise interacted with.
Using the static argument allows for static images to be produced instead.
pollroseMap( data, pollutant = NULL, statistic = "prop.count", breaks = NULL, latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )pollroseMap( data, pollutant = NULL, statistic = "prop.count", breaks = NULL, latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )
data |
Input data table with pollutant, wind, and geo-spatial information. required | scope: dynamic & static A data frame. The data frame must contain the data to plot the directional
analysis marker, which includes wind speed ( |
pollutant |
Pollutant name(s). required | scope: dynamic & static The column name(s) of the pollutant(s) to plot. If multiple pollutants are
specified and a non-pairwise statistic is supplied, the
Multiple |
statistic |
The statistic to be applied to each data bin in the plot default: Options currently include |
breaks |
Specifier for the number of breaks of the colour axis. default: Most commonly, the number of break points. If not specified, each marker
will independently break its supplied data at approximately 6 sensible
break points. When |
latitude, longitude
|
The decimal latitude(Y)/longitude(X). default: Column names representing the decimal latitude and longitude (or other Y/X
coordinate if using a different |
crs |
The coordinate reference system (CRS). default: The coordinate reference system (CRS) of the data, passed to
|
type |
A method to condition the default: Used for splitting the input data into different groups, passed to the
|
popup |
Content for marker popups on dynamic maps. default: Columns to be used as the HTML content for marker popups on dynamic maps.
Popups may be useful to show information about the individual sites (e.g.,
site names, codes, types, etc.). If a vector of column names are provided
they are passed to Numeric columns (e.g., pollutant concentrations) have many values at each
marker, so are averaged and labelled as such (e.g., "NO2
(mean)"). Names given to |
label |
Content for marker hover-over on dynamic maps. default: Column to be used as the HTML content for hover-over labels. Labels are
useful for the same reasons as popups, though are typically shorter. As
with |
provider |
The basemap(s) to be used. default: The base map(s) to be used for the map. If not provided, will default to
There is some overlap in static and dynamic providers. For example,
|
cols |
Colours to use for plotting. default: The colours used for plotting, passed to |
alpha |
Transparency value for polar markers. default: A value between 0 (fully transparent) and 1 (fully opaque). |
theme |
Custom ggplot2 theme for the polar markers. default: A custom |
key.position |
Legend position for individual marker legends. default: When |
legend |
Draw a shared legend? default: When all markers share the same colour scale, should a shared legend be created at the side of the map? This is the case for:
|
legend.position |
Position of the shared legend. default: When
|
legend.title |
Title of the legend. default: By default, when |
legend.title.autotext |
Automatically format the title of the legend? default: When |
control.collapsed |
Show the layer control as a collapsed? default: For dynamic maps, should the "layer control" interface be collapsed? If
|
control.position |
Position of the layer control menu default: When |
control.autotext |
Automatically format the content of the layer control menu? default: When |
d.icon |
The diameter of the plot on the map in pixels. default: This will affect the size of the individual polar markers. Alternatively, a
vector in the form |
d.fig |
The diameter of the plots to be produced using default: This will affect the resolution of the markers on the map. Alternatively, a
vector in the form |
static |
Produce a static map? default: This controls whether a dynamic or static map is produced. The former is the default and is broadly more useful, but the latter may be preferable for DOCX or PDF outputs (e.g., academic papers). |
static.nrow |
Number of rows in a static map. default: Controls the number of rows of panels on a static map when multiple
|
api_key |
API key for certain 'static' base map providers. default: Passed to the |
progress |
Show a progress bar? default: By default, a progress bar is shown to visualise the function's progress creating individual polar markers. This option allows this to be turned off, if desired. |
... |
Arguments passed on to
|
control |
Removed. Please use |
Either:
Dynamic: A leaflet object
Static: A ggplot2 object using ggplot2::coord_sf() coordinates with a ggspatial basemap
Creating a directional analysis map can take a lot of time; each polar
marker needs to be plot individually, and many of these require some
expensive computations. openairmaps supports parallel processing with
{mirai} to speed these computations up. Users may create workers by
running mirai::daemons() in their R session.
mirai::daemons(4) polarMap(polar_data, "no2")
Typically, spawning one fewer daemons than your number of available cores
is a useful rule of thumb. Parallel processing will be most useful for the
most computationally intensive plotting functions - i.e., polarMap() and
annulusMap().
As all static plots functions are ggplot2 figures, further customisation
is possible using functions such as ggplot2::theme(), ggplot2::guides()
and ggplot2::labs().
Subscripting pollutants (e.g., the "x" in "NOx") is achieved using the
ggtext package. Therefore if you choose to override the
plot theme, it is recommended to use [ggplot2::theme()] and
[ggtext::element_markdown()] to define the strip.text parameter.
Legends can be removed using ggplot2::theme(legend.position = "none"), or
further customised using ggplot2::guides() and either color = ggplot2::guide_colourbar() for continuous legends or color = ggplot2::guide_legend() for discrete legends.
The extent of a map can be adjusted using the xlim and ylim arguments
of ggplot2::coord_sf().
polarMap(polar_data, "no2", static = TRUE) +
ggplot2::coord_sf(
xlim = c(-0.3, 0.2),
ylim = c(51.2, 51.8)
)
Other directional analysis maps:
annulusMap(),
diffMap(),
freqMap(),
percentileMap(),
polarMap(),
windroseMap()
## Not run: pollroseMap(polar_data, pollutant = "nox", statistic = "prop.count", provider = "Esri.WorldGrayCanvas" ) ## End(Not run)## Not run: pollroseMap(polar_data, pollutant = "nox", statistic = "prop.count", provider = "Esri.WorldGrayCanvas" ) ## End(Not run)
openairmaps
Workhorse function that automatically applies routine text formatting to
common pollutant names which may be used in the HTML widgets produced by
openairmaps.
quickTextHTML(text)quickTextHTML(text)
text |
A character vector. required A character vector containing common pollutant names to be formatted. Commonly, this will insert super- and subscript HTML tags, e.g., "NO2" will be replaced with "NO2". |
quickTextHTML() is routine formatting lookup table. It screens the supplied
character vector text and automatically applies formatting to any
recognised character sub-series to properly render in HTML.
a character vector
Jack Davison.
openair::quickText(), useful for non-HTML/static maps and plots
labs <- c("no2", "o3", "so2") quickTextHTML(labs)labs <- c("no2", "o3", "so2") quickTextHTML(labs)
The traj_data dataset is provided as an example dataset as part of the
openairmaps package. The dataset contains HYSPLIT back trajectory data for
air mass parcels arriving in London in 2009. It has been joined with air
quality pollutant concentrations from the "London N. Kensington" AURN urban
background monitoring site.
traj_datatraj_data
An object of class tbl_df (inherits from tbl, data.frame) with 5432 rows and 17 columns.
The arrival time of the air-mass
The receptor number
Trajectory year
Trajectory month
Trajectory day
Trajectory hour
Trajectory hour offset from the arrival date
Latitude
Longitude
Height of trajectory in m
Pressure of the trajectory in Pa
Date of the trajectory
Concentration of oxides of nitrogen (NO + NO2)
Concentration of nitrogen dioxide (NO2)
Concentration of ozone (O3)
Concentration of particulates (PM10)
Concentration of fine particulates (PM2.5)
traj_data was compiled from data using the openair::importTraj()
function from the openair package with air quality data from
openair::importAURN() function.
traj_datatraj_data
leaflet
This function plots back trajectories on a leaflet map. This function
requires that data are imported using the openair::importTraj() function.
trajLevelMap( data, latitude = NULL, longitude = NULL, pollutant = NULL, type = NULL, smooth = FALSE, statistic = "frequency", percentile = 90, lon.inc = 1, lat.inc = 1, breaks = NULL, min.bin = 1, .combine = NULL, sigma = 1.5, cols = "turbo", alpha = 0.5, tile.border = NA, provider = "OpenStreetMap", legend.position = "topright", legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", ... )trajLevelMap( data, latitude = NULL, longitude = NULL, pollutant = NULL, type = NULL, smooth = FALSE, statistic = "frequency", percentile = 90, lon.inc = 1, lat.inc = 1, breaks = NULL, min.bin = 1, .combine = NULL, sigma = 1.5, cols = "turbo", alpha = 0.5, tile.border = NA, provider = "OpenStreetMap", legend.position = "topright", legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", ... )
data |
A data frame containing a HYSPLIT trajectory, perhaps accessed
with required A data frame containing HYSPLIT model outputs. If this data were not
obtained using |
latitude, longitude
|
The decimal latitude/longitude. default: Column names representing the decimal latitude and longitude. If not
provided, will be automatically inferred from data by looking for a column
named "lat"/"latitude" or "lon"/"lng"/"long"/"longitude"
(case-insensitively), such as the "lat" and "lon" columns returned by
|
pollutant |
The pollutant of interest. Not required when |
type |
A method to condition the default: Used for splitting the trajectories into different groups which can be
selected between using a "layer control" menu. Passed to
|
smooth |
Should the trajectory surface be smoothed? Defaults to |
statistic |
One of:
|
percentile |
The percentile concentration of |
lon.inc, lat.inc
|
The longitude and latitude intervals to be used for
binning data. If |
breaks |
|
min.bin |
The minimum number of unique points in a grid cell. Counts
below |
.combine |
When statistic is "SQTBA" it is possible to combine lots of
receptor locations to derive a single map. |
sigma |
For the SQTBA approach |
cols |
Colours to use for plotting. default: The colours used for plotting, passed to |
alpha |
Transparency value for trajectories. default: A value between |
tile.border |
Colour to use for the border of binned tiles. Defaults to
|
provider |
The basemap(s) to be used. default: Any number of leaflet::providers. See
http://leaflet-extras.github.io/leaflet-providers/preview/ for a list of
all base maps that can be used. If multiple base maps are provided, they
can be toggled between using a "layer control" interface. By default, the
interface will use the provider names as labels, but users can define their
own using a named vector (e.g., |
legend.position |
Position of the shared legend. default: Where should the legend be placed? One of "topright", "topleft",
"bottomleft" or "bottomright". Passed to the |
legend.title |
Title of the legend. default: By default, when |
legend.title.autotext |
Automatically format the title of the legend? default: When |
control.collapsed |
Show the layer control as a collapsed? default: Should the "layer control" interface be collapsed? If |
control.position |
Position of the layer control menu default: Where should the "layer control" interface be placed? One of "topleft",
"topright", "bottomleft" or "bottomright". Passed to the |
... |
Arguments passed on to
|
A leaflet object.
addTrajLevel() to add gridded trajectory statistics to any
leaflet map
Other interactive trajectory maps:
trajMap()
## Not run: trajLevelMap(traj_data, pollutant = "pm2.5", statistic = "pscf", min.bin = 10) ## End(Not run)## Not run: trajLevelMap(traj_data, pollutant = "pm2.5", statistic = "pscf", min.bin = 10) ## End(Not run)
leaflet
This function plots back trajectories on a leaflet map. This function
requires that data are imported using the openair::importTraj() function.
Options are provided to colour the individual trajectories (e.g., by
pollutant concentrations) or create "layer control" menus to show/hide
different layers.
trajMap( data, latitude = NULL, longitude = NULL, colour = NULL, type = NULL, cols = "turbo", alpha = 0.5, npoints = 12, provider = "OpenStreetMap", legend.position = "topright", legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", ... )trajMap( data, latitude = NULL, longitude = NULL, colour = NULL, type = NULL, cols = "turbo", alpha = 0.5, npoints = 12, provider = "OpenStreetMap", legend.position = "topright", legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", ... )
data |
A data frame containing a HYSPLIT trajectory, perhaps accessed
with required A data frame containing HYSPLIT model outputs. If this data were not
obtained using |
latitude, longitude
|
The decimal latitude/longitude. default: Column names representing the decimal latitude and longitude. If not
provided, will be automatically inferred from data by looking for a column
named "lat"/"latitude" or "lon"/"lng"/"long"/"longitude"
(case-insensitively), such as the "lat" and "lon" columns returned by
|
colour |
Column to be used for colouring each trajectory. default: This column may be numeric, character, factor or date(time). This will
commonly be a pollutant concentration which has been joined (e.g., by
|
type |
A method to condition the default: Used for splitting the trajectories into different groups which can be
selected between using a "layer control" menu. Passed to
|
cols |
Colours to use for plotting. default: The colours used for plotting, passed to |
alpha |
Transparency value for trajectories. default: A value between |
npoints |
Interval at which points are placed along the trajectory paths. default: A dot is placed every |
provider |
The basemap(s) to be used. default: Any number of leaflet::providers. See
http://leaflet-extras.github.io/leaflet-providers/preview/ for a list of
all base maps that can be used. If multiple base maps are provided, they
can be toggled between using a "layer control" interface. By default, the
interface will use the provider names as labels, but users can define their
own using a named vector (e.g., |
legend.position |
Position of the shared legend. default: Where should the legend be placed? One of "topright", "topleft",
"bottomleft" or "bottomright". Passed to the |
legend.title |
Title of the legend. default: By default, when |
legend.title.autotext |
Automatically format the title of the legend? default: When |
control.collapsed |
Show the layer control as a collapsed? default: Should the "layer control" interface be collapsed? If |
control.position |
Position of the layer control menu default: Where should the "layer control" interface be placed? One of "topleft",
"topright", "bottomleft" or "bottomright". Passed to the |
... |
Arguments passed on to
|
A leaflet object.
Other interactive trajectory maps:
trajLevelMap()
## Not run: trajMap(traj_data, colour = "pm10") ## End(Not run)## Not run: trajMap(traj_data, colour = "pm10") ## End(Not run)
The windroseMap() function creates a map using wind roses as markers.
Multiple layers of markers can be created using the type argument. By
default, these maps are dynamic and can be panned, zoomed, and otherwise
interacted with. Using the static argument allows for static images to be
produced instead.
windroseMap( data, ws.int = 2, breaks = 4, latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )windroseMap( data, ws.int = 2, breaks = 4, latitude = NULL, longitude = NULL, crs = 4326, type = NULL, popup = NULL, label = NULL, provider = "OpenStreetMap", cols = "turbo", alpha = 1, theme = "default", key.position = "none", legend = TRUE, legend.position = NULL, legend.title = NULL, legend.title.autotext = TRUE, control.collapsed = FALSE, control.position = "topright", control.autotext = TRUE, d.icon = 200, d.fig = 3.5, static = FALSE, static.nrow = NULL, api_key = NULL, progress = TRUE, ..., control = NULL )
data |
Input data table with wind and geo-spatial information. required | scope: dynamic & static A data frame. The data frame must contain the data to plot the directional
analysis marker, which includes wind speed ( |
ws.int |
The wind speed interval of the colour axis. default: The wind speed interval. Default is 2 m/s but for low met masts with low mean wind speeds a value of 1 or 0.5 m/s may be better. |
breaks |
Specifier for the number of breaks of the colour axis. default: Most commonly, the number of break points for wind speed in
|
latitude, longitude
|
The decimal latitude(Y)/longitude(X). default: Column names representing the decimal latitude and longitude (or other Y/X
coordinate if using a different |
crs |
The coordinate reference system (CRS). default: The coordinate reference system (CRS) of the data, passed to
|
type |
A method to condition the default: Used for splitting the input data into different groups, passed to the
|
popup |
Content for marker popups on dynamic maps. default: Columns to be used as the HTML content for marker popups on dynamic maps.
Popups may be useful to show information about the individual sites (e.g.,
site names, codes, types, etc.). If a vector of column names are provided
they are passed to Numeric columns (e.g., pollutant concentrations) have many values at each
marker, so are averaged and labelled as such (e.g., "NO2
(mean)"). Names given to |
label |
Content for marker hover-over on dynamic maps. default: Column to be used as the HTML content for hover-over labels. Labels are
useful for the same reasons as popups, though are typically shorter. As
with |
provider |
The basemap(s) to be used. default: The base map(s) to be used for the map. If not provided, will default to
There is some overlap in static and dynamic providers. For example,
|
cols |
Colours to use for plotting. default: The colours used for plotting, passed to |
alpha |
Transparency value for polar markers. default: A value between 0 (fully transparent) and 1 (fully opaque). |
theme |
Custom ggplot2 theme for the polar markers. default: A custom |
key.position |
Legend position for individual marker legends. default: When |
legend |
Draw a shared legend? default: When all markers share the same colour scale, should a shared legend be created at the side of the map? This is the case for:
|
legend.position |
Position of the shared legend. default: When
|
legend.title |
Title of the legend. default: By default, when |
legend.title.autotext |
Automatically format the title of the legend? default: When |
control.collapsed |
Show the layer control as a collapsed? default: For dynamic maps, should the "layer control" interface be collapsed? If
|
control.position |
Position of the layer control menu default: When |
control.autotext |
Automatically format the content of the layer control menu? default: When |
d.icon |
The diameter of the plot on the map in pixels. default: This will affect the size of the individual polar markers. Alternatively, a
vector in the form |
d.fig |
The diameter of the plots to be produced using default: This will affect the resolution of the markers on the map. Alternatively, a
vector in the form |
static |
Produce a static map? default: This controls whether a dynamic or static map is produced. The former is the default and is broadly more useful, but the latter may be preferable for DOCX or PDF outputs (e.g., academic papers). |
static.nrow |
Number of rows in a static map. default: Controls the number of rows of panels on a static map when multiple
|
api_key |
API key for certain 'static' base map providers. default: Passed to the |
progress |
Show a progress bar? default: By default, a progress bar is shown to visualise the function's progress creating individual polar markers. This option allows this to be turned off, if desired. |
... |
Arguments passed on to
|
control |
Removed. Please use |
Either:
Dynamic: A leaflet object
Static: A ggplot2 object using ggplot2::coord_sf() coordinates with a ggspatial basemap
Creating a directional analysis map can take a lot of time; each polar
marker needs to be plot individually, and many of these require some
expensive computations. openairmaps supports parallel processing with
{mirai} to speed these computations up. Users may create workers by
running mirai::daemons() in their R session.
mirai::daemons(4) polarMap(polar_data, "no2")
Typically, spawning one fewer daemons than your number of available cores
is a useful rule of thumb. Parallel processing will be most useful for the
most computationally intensive plotting functions - i.e., polarMap() and
annulusMap().
As all static plots functions are ggplot2 figures, further customisation
is possible using functions such as ggplot2::theme(), ggplot2::guides()
and ggplot2::labs().
Subscripting pollutants (e.g., the "x" in "NOx") is achieved using the
ggtext package. Therefore if you choose to override the
plot theme, it is recommended to use [ggplot2::theme()] and
[ggtext::element_markdown()] to define the strip.text parameter.
Legends can be removed using ggplot2::theme(legend.position = "none"), or
further customised using ggplot2::guides() and either color = ggplot2::guide_colourbar() for continuous legends or color = ggplot2::guide_legend() for discrete legends.
The extent of a map can be adjusted using the xlim and ylim arguments
of ggplot2::coord_sf().
polarMap(polar_data, "no2", static = TRUE) +
ggplot2::coord_sf(
xlim = c(-0.3, 0.2),
ylim = c(51.2, 51.8)
)
Other directional analysis maps:
annulusMap(),
diffMap(),
freqMap(),
percentileMap(),
polarMap(),
pollroseMap()
## Not run: windroseMap(polar_data, provider = "Esri.WorldGrayCanvas" ) ## End(Not run)## Not run: windroseMap(polar_data, provider = "Esri.WorldGrayCanvas" ) ## End(Not run)