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
type
is"seq"
or"div"
, the function will return a discrete color spectrum withn
colorsIf the value is an integer number and
type
is"qual"
, the function will returnn
colors from thecolors
parameter, repeating them if necessaryIf the value is a
numeric
vector between0
and1
, the function will return the color positions atn
considering a continuous color spectrum ranging from0
to1
- colors
(Optional) A
character
vector of colors to use in the scale. IfNULL
,brandr
will choose the colors based on thetype
argument.- type
(Optional) A
character
string indicating the type of color scale:"seq"
/"sequential"
,"div"
/"diverging"
, or"qual"
/"qualitative"
(Default:seq
).- alpha
(Optional) A number between
0
and1
, indicating the transparency of the colors (Default:NULL
).- direction
(Optional) A number (
1
or-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