key_group | R Documentation |
These functions are helper functions for working with grouped data as keys in guides. They all share the goal of creating a guide key, but have different methods.
key_group_split()
is a function factory whose functions make an attempt
to infer groups from the scale's labels.
key_group_lut()
is a function factory whose functions use a look up table
to sort out group membership.
key_group_split(sep = "[^[:alnum:]]+", reverse = FALSE)
key_group_lut(members, group, ungrouped = "Other")
sep |
A |
reverse |
A |
members |
A vector including the scale's |
group |
A vector parallel to |
ungrouped |
A |
A function to use as the key
argument in a guide.
Other keys:
key_range
,
key_segments
,
key_specialty
,
key_standard
# Example scale
values <- c("group A:value 1", "group A:value 2", "group B:value 1")
template <- scale_colour_hue(limits = values)
# Treat the 'group X' part as groups
key <- key_group_split(sep = ":")
key(template)
# Treat the 'value X' part as groups
key <- key_group_split(sep = ":", reverse = TRUE)
key(template)
# Example scale
template <- scale_colour_hue(limits = msleep$name[c(1, 7, 9, 23, 24)])
# A lookup table can have more entries than needed
key <- key_group_lut(msleep$name, msleep$order)
key(template)
# Or less entries than needed
key <- key_group_lut(
msleep$name[23:24], msleep$order[23:24],
ungrouped = "Other animals"
)
key(template)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.