buildPopup | R Documentation |
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,
cols,
latitude = NULL,
longitude = NULL,
names = NULL,
control = 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 ")
)
data |
A data frame containing latitude and longitude information that
will go on to be used in a function such as |
cols |
A character vector of column names, the data from which will appear in the popup. |
latitude, longitude |
The decimal latitude/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). |
names |
Optional. A named vector used to rename certain columns in the popups. See the Example for more information. |
control |
Optional. Column which will be used for the |
fun.character |
A function to summarise character and factor columns. Defaults to collapsing unique values into a comma-separated list. |
fun.numeric |
A function to summarise numeric columns. Defaults to taking the mean to three significant figures. |
fun.dttm |
A function to summarise date columns. Defaults to presenting the date as a range. |
a tibble::tibble()
## Not run:
buildPopup(
data = openairmaps::polar_data,
cols = c("site", "site_type", "date", "nox"),
names = c("Site" = "site", "Site Type" = "site_type", "Date Range" = "date")
) %>%
polarMap("nox", popup = "popup")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.