Learn R Programming

ggh4x (version 0.2.2)

distribute_args: Element list constructors

Description

These functions take a vector of arguments and pass on the ith item of the vector to an ith call of a function. The elem_list_text and elem_list_rect are convenience functions for constructing lists of element_text() and element_rect() theme elements.

Usage

distribute_args(..., .fun = element_text, .cull = TRUE)

elem_list_text(...)

elem_list_rect(...)

Value

A list of outputs from fun.

Arguments

...

Vectorised arguments to pass on to functions.

.fun

A function to distribute arguments to.

.cull

A logical(1) determining if unknown arguments are being culled.

Details

NAs and NULLs will be silently dropped. If you want to pass on a transparent fill or colour argument, you should use the more verbose character "transparent" instead. However, you can use a NA to indicate that it's argument should not be passed to a function in that position.

See Also

The element_text() and element_rect() theme elements for a description of their arguments.

Examples

Run this code
# Providing arguments for `element_rect()`
elem_list_rect(
  # The first element_rect will have linetype 1, the second gets 3
  linetype = c(1, 3),
  # If an argument doesn't exist, it will be silently dropped
  nonsense_argument = c("I", "will", "be", "filtered", "out")
)

# Providing arguments for `element_text()`
elem_list_text(
  # `NA`s will be skipped
  family = c("mono", NA, "sans"),
  # Providing a list of more complex arguments. `NULL` will be skipped too.
  margin = list(NULL, margin(t = 5))
)

# Providing arguments to other functions
distribute_args(
  lineend = c("round", "butt", "square"),
  # If you want to pass a vector instead of a scalar, you can use a list
  colour = list(c("blue", "red"), "green"),
  .fun = element_line
)

Run the code above in your browser using DataLab