Skip to content

Commit

Permalink
allow guide_axis_nested(key) to be a sep argument
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Dec 13, 2024
1 parent 3f76efd commit 4e09fb2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions R/guide_axis_nested.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
#' This axis guide gives extra range annotations to position scales. It can
#' be used to infer nesting structure from labels or annotate ranges.
#'
#' @param key A [range key][key_range] specification. If not
#' `key = "range_auto"`, additional labels will be inserted to represent
#' point values.
#' @param key One of the following:
#' * A [range key][key_range] specification. If not `key = "range_auto"`,
#' additional labels will be inserted to represent point values.
#' * A `<character[1]>` passed to the [`key_range_auto(sep)`][key_range_auto]
#' argument. An exception is made when the string is a valid key
#' specification.
#' @param regular_key A [standard key][key_standard] specification for the
#' appearance of regular tick marks.
#' @param type Appearance of ranges, either `"box"` to put text in boxes or
Expand Down Expand Up @@ -106,6 +109,9 @@ guide_axis_nested <- function(
)
pad_discrete <- pad_discrete %||% switch(type, fence = 0.5, 0.4)

if (is_string(key) && !is_key_string(key)) {
key <- key_range_auto(sep = key)
}
if (identical(key, "range_auto") ||
inherits(key, "key_range_auto_function")) {
labels <- guide_none()
Expand Down
8 changes: 8 additions & 0 deletions R/key-.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ resolve_key <- function(x, allow_null = FALSE) {
cli::cli_abort("Unknown key specification: {x}.")
}

is_key_string <- function(x) {
if (!is_bare_string(x)) {
return(FALSE)
}
fun <- find_global(paste0("key_", x), env = global_env(), mode = "function")
is.function(fun)
}

log10_keys <- function(scale, aesthetic,
prescale_base = NULL,
negative_small = 0.1,
Expand Down

0 comments on commit 4e09fb2

Please sign in to comment.