Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pairwise statistics in polarMap() #73

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: openairmaps
Title: Create Maps of Air Pollution Data
Version: 0.9.0.9000
Version: 0.9.0.9001
Authors@R: c(
person("Jack", "Davison", , "[email protected]", role = c("cre", "aut")),
person("David", "Carslaw", , "[email protected]", role = "aut")
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# openairmaps (development version)

## New features

* Pairwise statistics (e.g., `"robust_slope"`) are now supported by `polarMap()`. (#72)

## Bug fixes

* Vectors greater than length 1 passed to `popup` in the `polarMap()` argument will no longer error when `type = NULL`.
Expand Down
44 changes: 37 additions & 7 deletions R/polar_polarMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
#' **required** | *scope:* dynamic & static
#'
#' The column name(s) of the pollutant(s) to plot. If multiple pollutants are
#' specified the `type` argument will no longer be able to be used, and:
#' specified and a non-pairwise statistic is supplied, the `type` argument
#' will no longer be able to be used and:
#'
#' - *Dynamic*: The pollutants can be toggled between using a "layer control" menu.
#'
#' - *Static:*: The pollutants will each appear in a different panel.
#'
#' Multiple `pollutants` prohibit the use of the `type` argument.
#' Multiple `pollutants` prohibit the use of the `type` argument for
#' non-pairwise statistics.
#'
#' @param x *The radial axis variable.*
#'
Expand Down Expand Up @@ -317,6 +319,21 @@ polarMap <- function(data,
static.nrow = NULL,
...,
control = NULL) {
# list pairwise statistics
pairwise_stats <- c("r",
"Pearson",
"Spearman",
"robust_slope",
"quantile.slope",
"york_slope")
dots <- rlang::list2(...)
pairwise_flag <- FALSE
if ("statistic" %in% names(dots)) {
if (dots$statistic %in% pairwise_stats) {
pairwise_flag <- TRUE
}
}

# check basemap providers are valid
provider <- check_providers(provider, static)
legend.position <- check_legendposition(legend.position, static)
Expand All @@ -334,7 +351,9 @@ polarMap <- function(data,
longitude <- latlon$longitude

# auto limits
limits <- check_multipoll(limits, pollutant)
if (!pairwise_flag) {
limits <- check_multipoll(limits, pollutant)
}

if ("fixed" %in% limits) {
data <-
Expand Down Expand Up @@ -403,24 +422,34 @@ polarMap <- function(data,
latitude,
longitude,
popup,
label
label,
.to_narrow = !pairwise_flag,
.pairwise = pairwise_flag
)

# identify splitting column (defaulting to pollutant)
if (length(pollutant) > 1) {
if (length(pollutant) > 1 && !pairwise_flag) {
split_col <- "pollutant_name"
} else if (!is.null(type)) {
data[type] <- as.factor(data[[type]])
split_col <- type
} else if (pairwise_flag) {
data$pollutant_name <- "DUMMY"
split_col <- "pollutant_name"
} else {
split_col <- "pollutant_name"
}

# define function
if (pairwise_flag) {
funpoll <- pollutant
} else {
funpoll <- "conc"
}
fun <- function(data) {
openair::polarPlot(
data,
pollutant = "conc",
pollutant = funpoll,
x = x,
plot = FALSE,
limits = theLimits,
Expand All @@ -443,7 +472,8 @@ polarMap <- function(data,
split_col = split_col,
d.fig = d.fig,
popup = popup,
label = label
label = label,
dropcol = funpoll
)

if (!static) {
Expand Down
8 changes: 4 additions & 4 deletions R/utils-map.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ checkMapPrep <-
#' Prep data for mapping
#' @noRd
prepMapData <-
function(data, pollutant, control, ..., .to_narrow = TRUE) {
function(data, pollutant, control, ..., .to_narrow = TRUE, .pairwise = FALSE) {
# check pollutant is there
if (is.null(pollutant)) {
cli::cli_abort(
Expand All @@ -179,11 +179,11 @@ prepMapData <-
}

# check if more than one pollutant & is.null split
if (length(pollutant) > 1 & !is.null(control)) {
if (length(pollutant) > 1 & !is.null(control) & !.pairwise) {
cli::cli_warn(
c(
"!" = "Multiple pollutants {.emph and} {.code control/facet} option specified",
"i" = "Please only specify multiple pollutants {.emph or} a {.code control/facet} option",
"!" = "Multiple pollutants {.emph and} {.code type} option specified",
"i" = "Please only specify multiple pollutants {.emph or} a {.code type} option",
"i" = "Defaulting to splitting by {.code pollutant}"
)
)
Expand Down
6 changes: 4 additions & 2 deletions man/annulusMap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/deprecated-static-polar-maps.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/freqMap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/percentileMap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/polarMap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/pollroseMap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading