key_segments: Segment keys

key_segmentsR Documentation

Segment keys

Description

These functions are helper functions for working with segment data as keys in guides. They all share the goal of creating a guide key, but have different methods:

  • key_segment_manual() directly uses user-provided vectors to set segments.

  • key_segment_map() makes mappings from a ⁠<data.frame>⁠ to set segments.

  • key_dendro() is a specialty case for coercing dendrogram data to segments. Be aware that setting the key alone cannot affect the scale limits, and will give misleading results when used incorrectly!

Usage

key_segment_manual(value, oppo, value_end = value, oppo_end = oppo, ...)

key_segment_map(data, ..., .call = caller_env())

key_dendro(dendro = NULL, type = "rectangle")

Arguments

value, value_end

A vector that is interpreted to be along the scale that the guide codifies.

oppo, oppo_end

A vector that is interpreted to be orthogonal to the value and value_end variables.

...

<data-masking> A set of mappings similar to those provided to aes(), which will be evaluated in the data argument. For key_segments_map(), these must contain value and oppo mappings.

data

A ⁠<data.frame>⁠ or similar object coerced by fortify() to a ⁠<data.frame>⁠, in which the mapping argument is evaluated.

.call

A call to display in messages.

dendro

A data structure that can be coerced to a dendrogram through the as.dendrogram() function. When NULL (default) an attempt is made to search for such data in the scale.

type

A string, either "rectangle" or "triangle", indicating the shape of edges between nodes of the dendrogram.

Value

For key_segments_manual() and key_segments_map(), a ⁠<data.frame>⁠ with the ⁠<key_range>⁠ class.

See Also

Other keys: key_group, key_range, key_specialty, key_standard

Examples

# Giving vectors directly
key_segment_manual(
  value = 0:1, value_end = 2:3,
  oppo  = 1:0, oppo_end  = 3:2
)

# Taking columns of a data frame
data <- data.frame(x = 0:1, y = 1:0, xend = 2:3, yend = 3:2)
key_segment_map(data, value = x, oppo = y, value_end = xend, oppo_end = yend)

# Using dendrogram data
clust <- hclust(dist(USArrests), "ave")
key_dendro(clust)(scale_x_discrete())

legendry documentation built on April 4, 2025, 2:12 a.m.