key_range | R Documentation |
These functions are helper functions for working with ranged data as keys in guides. They all share the goal creating of a guide key, but have different methods:
key_range_auto()
is a function factory whose functions make an attempt
to infer ranges from the scale's labels.
key_range_manual()
uses user-provided vectors to set ranges.
key_range_map()
makes mappings from a <data.frame>
to set ranges.
key_range_auto(sep = "[^[:alnum:]]+", reverse = FALSE, ...)
key_range_manual(start, end, name = NULL, level = NULL, ...)
key_range_map(data, ..., .call = caller_env())
sep |
A |
reverse |
A |
... |
|
start , end |
A vector that can be interpreted by the scale, giving the start and end positions of each range respectively. |
name |
A |
level |
An |
data |
A |
.call |
A call to display in messages. |
The level
variable is optional and when missing, the guides use an
algorithm similar to IRanges::disjointBins()
to avoid overlaps.
The key_range_auto()
does not work with expression labels.
For key_range_auto()
a function. For key_range_manual()
and
key_range_map()
a <data.frame>
with the <key_range>
class.
Other keys:
key_group
,
key_segments
,
key_specialty
,
key_standard
# Example scale
template <- scale_x_discrete(limits = c("A 1", "B 1", "C&1", "D&2", "E&2"))
# By default, splits on all non-alphanumeric characters
auto <- key_range_auto()
auto(template)
# Only split on a specific character
auto <- key_range_auto(sep = "&")
auto(template)
# Treating the letters as outer labels and numbers as inner labels
auto <- key_range_auto(reverse = TRUE)
auto(template)
# Providing custom values
key_range_manual(
start = c(1, 5, 10),
end = c(4, 15, 11),
level = c(0, 2, 1),
name = c("A", "B", "C")
)
# Values from a <data.frame>
key_range_map(presidential, start = start, end = end, name = name)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.