Skip to contents

Create a color interpolation function based on one of the predefined tscv palettes.

Usage

tscv_pal(palette = "main", reverse = FALSE, ...)

Arguments

palette

Character value. Name of the palette.

reverse

Logical value. If TRUE, the palette is reversed.

...

Additional arguments passed to grDevices::colorRampPalette().

Value

A palette function that takes an integer and returns hexadecimal color codes.

Details

tscv_pal() returns a palette function created with grDevices::colorRampPalette(). The returned function can be used to generate any number of colors from the selected palette.

Available palettes are:

  • "main": blue, green, yellow.

  • "cool": blue, green.

  • "hot": yellow, orange, red.

  • "mixed": blue, green, yellow, orange, red.

  • "grey": light grey, dark grey.

Examples

# Create a palette function
pal <- tscv_pal("main")

# Generate five colors
pal(5)
#> [1] "#4682B4" "#96905A" "#E69F00" "#739E39" "#009E73"

# Reverse the palette
tscv_pal("hot", reverse = TRUE)(5)
#> [1] "#F0E442" "#E2A121" "#D55E00" "#DD7E00" "#E69F00"

# Use generated colors in base R
barplot(
  height = c(3, 5, 4),
  col = tscv_pal("main")(3)
)