Returns n colors from the named character's palette, either the first
n curated colors (type = "discrete") or n colors interpolated
across the whole palette (type = "continuous").
Usage
tf_palette(
name,
n = NULL,
type = c("discrete", "continuous"),
strict = TRUE,
sort = FALSE,
medium = "toy"
)Arguments
- name
Palette name. Case-insensitive, and spaces or hyphens may stand in for underscores, so
"Optimus Prime"and"Hun-Gurrr"work. Seetf_palette_names(). A full name with a medium suffix ("megatron_cartoon") also works and takes precedence overmedium.- n
Number of colors wanted. Defaults to every color in the palette.
- type
Either
"discrete"(default) to return the curated colors as they are, or"continuous"to interpolatencolors across the palette withgrDevices::colorRampPalette().- strict
Logical. For discrete palettes, error when
nexceeds the number of curated colors (default). IfFALSE, interpolate toncolors instead.- sort
Logical. If
TRUE, order the colors from darkest to lightest (by CIE lightness) before selecting or interpolating. Useful when a palette is used as a sequential gradient; seetf_find_palettes().- medium
Which version of the character to use:
"toy"(default),"cartoon","comic"or"g2". Seetf_media(). Errors with a pointer to the wishlist if the character has no palette in that medium.
Value
A character vector of hex colors with class "tf_palette", which
has a print method that draws the swatches.
Examples
tf_palette("optimus_prime")
#> Transformers palette 'optimus_prime' (5 colors, toy)
#> Autobot: Optimus Prime
#> #D0202A #1F3E8F #B8BABF #F2D23C #2D2D2D
tf_palette("optimus_prime", medium = "cartoon")
#> Transformers palette 'optimus_prime_cartoon' (5 colors, cartoon)
#> Autobot: Optimus Prime
#> #D9262C #2244A0 #A9AEB3 #8FCBE8 #4A4F55
tf_palette("Megatron", 3, medium = "comic")
#> Transformers palette 'megatron_comic' (3 colors, comic)
#> Decepticon: Megatron
#> #B9BDC2 #5E6368 #2B2B2B
tf_palette("devastator", medium = "g2")
#> Transformers palette 'devastator_g2' (5 colors, g2)
#> Decepticon / Constructicons: Devastator
#> #F2D21E #6E3FA3 #B5B8BD #262626 #F07C1E
tf_palette("devastator", 12, type = "continuous")
#> Transformers palette 'devastator' (12 colors, toy)
#> Decepticon / Constructicons: Devastator
#> #3FA23F #507D63 #615987 #7449A5 #8E76AE #A8A2B8 #9B9DA1 #67686A #323333 #5B502B #A28933 #E9C23B
tf_palette("hot_spot", 12, type = "continuous", sort = TRUE)
#> Transformers palette 'hot_spot' (12 colors, toy)
#> Autobot / Protectobots: Hot Spot
#> #2A2A2A #26395A #22498B #2F51A3 #704173 #B13142 #C73E3F #B3686A #9F9296 #B2B4B6 #D2D3D3 #F2F2F0
# base graphics
barplot(1:5, col = tf_palette("predaking"))