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 = FALSE,
d.icon = 200,
d.fig = 3.5,
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 = FALSE,
d.icon = 200,
d.fig = 3.5,
...
)
A leaflet object.
a map widget object created from leaflet()
The name of the pollutant to be plot. Note that, if fun = openair::windRose
, you must set pollutant = "ws"
.
An openair
directional analysis plotting function. Supported
functions include openair::polarPlot()
(the default),
openair::polarAnnulus()
, openair::polarFreq()
,
openair::percentileRose()
, openair::pollutionRose()
and
openair::windRose()
. For openair::polarDiff()
, use
addPolarDiffMarkers()
.
The decimal longitude.
The decimal latitude.
the layer id
the name of the group the newly created layers should belong to
(for clearGroup
and addLayersControl
purposes).
Human-friendly group names are permitted--they need not be short,
identifier-style names. Any number of layers and even different types of
layers (e.g. markers and polygons) can share the same group name.
A column of data
to be used as a popup.
A Vector of popupOptions
to provide popups
A column of data
to be used as a label.
A Vector of labelOptions
to provide label
options for each label. Default NULL
a list of extra options for tile layers, popups, paths (circles, rectangles, polygons, ...), or other map elements
if not NULL
, markers will be clustered using
Leaflet.markercluster;
you can use markerClusterOptions()
to specify marker cluster
options
the id for the marker cluster layer
Should a key for each marker be drawn? Default is FALSE
.
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 c(width, height)
can be provided if a non-circular marker is
desired.
The diameter of the plots to be produced using openair
in
inches. This will affect the resolution of the markers on the map.
Alternatively, a vector in the form c(width, height)
can be provided if a
non-circular marker is desired.
A data frame. The data frame must contain the data to plot your
choice of openair directional analysis plot, which includes wind speed
(ws
), wind direction (wd
), and the column representing the
concentration of a pollutant. In addition, data
must include a decimal
latitude and longitude. By default, it is the data object provided to
leaflet::leaflet()
initially, but can be overridden.
Other arguments for the plotting function (e.g. period
for
openair::polarAnnulus()
).
A data frame that represents the before/after case. See
openair::polarPlot()
for details of different input requirements. By
default, both before
and after
are the data object provided to
leaflet::leaflet()
initially, but at least one should be overridden.
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()
if (FALSE) {
library(leaflet)
library(openair)
# different types of polar plot on one map
leaflet(data = polar_data) %>%
addTiles() %>%
addPolarMarkers("ws",
fun = openair::windRose,
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))
)
}
Run the code above in your browser using DataLab