interpolate_colors() interpolate colors for sequential, diverging,
and qualitative color scales.
Usage
interpolate_colors(
n,
colors = getOption("BRANDR_COLOR_SEQUENTIAL"),
type = "seq",
alpha = NULL,
direction = 1,
...
)Arguments
- n
This parameter accepts two types of inputs:
If the value is an integer number and
typeis"seq"or"div", the function will return a discrete color spectrum withncolorsIf the value is an integer number and
typeis"qual", the function will returnncolors from thecolorsparameter, repeating them if necessaryIf the value is a
numericvector between0and1, the function will return the color positions atnconsidering a continuous color spectrum ranging from0to1
- colors
(Optional) A
charactervector of colors to use in the scale. IfNULL,brandrwill choose the colors based on thetypeargument.- type
(Optional) A
characterstring indicating the type of color scale:"seq"/"sequential","div"/"diverging", or"qual"/"qualitative"(Default:seq).- alpha
(Optional) A number between
0and1, indicating the transparency of the colors (Default:NULL).- direction
(Optional) A number (
1or-1) indicating the direction of the colors. If1, the order remains the same. If-1, the order is reversed. (Default:1).- ...
Additional arguments passed to
colorRampPalette()when creating the color ramp. Only valid when type is"seq"or"div".
Value
A character vector with
hexadecimal color codes.
See also
Other color functions:
color_brand_sequential()
Examples
interpolate_colors(3, colors = c("red", "blue"), type = "seq")
#> [1] "#FF0000" "#7F007F" "#0000FF"
#> [1] "#FF0000" "#7F007F" "#0000FF" # Expected
interpolate_colors(3, colors = c("red", "blue"), direction = -1)
#> [1] "#0000FF" "#7F007F" "#FF0000"
#> [1] "#0000FF" "#7F007F" "#FF0000" # Expected
interpolate_colors(3, colors = c("red", "blue"), alpha = 0.5)
#> [1] "#FF000080" "#7F007F80" "#0000FF80"
#> [1] "#FF000080" "#7F007F80" "#0000FF80" # Expected
# `type = "seq"` and `type = "div"` produce the same result
interpolate_colors(3, colors = c("red", "white", "blue"), type = "div")
#> [1] "#FF0000" "#FFFFFF" "#0000FF"
#> [1] "#FF0000" "#FFFFFF" "#0000FF" # Expected
interpolate_colors(3, colors = c("red", "blue"), type = "qual")
#> [1] "#FF0000" "#0000FF" "#FF0000"
#> [1] "#FF0000" "#0000FF" "#FF0000" # Expected
