R/colorjam-rainbowjam.R
rainbowJam.Rd
rainbow categorical colors using varied luminance and chroma
rainbowJam(
n = NULL,
preset = getOption("colorjam.preset", "dichromat2"),
step = getOption("colorjam.step", "default"),
Hstart = 0,
alpha = 1,
hues = NULL,
warpHue = NULL,
h1 = NULL,
h2 = NULL,
Cvals = NULL,
Lvals = NULL,
Crange = NULL,
Lrange = NULL,
phase = 1,
direction = c("1", "-1"),
do_hue_pad = FALSE,
hue_pad_percent = 0,
nameStyle = c("none", "n", "closest_named_color", "closestRcolor", "hcl", "color"),
doTest = FALSE,
verbose = FALSE,
...
)
integer
number of categorical colors to return
character
string matching one entry in colorjam_presets()
,
which defines the color wheel to use.
define the color wheel, only used when warpHue=TRUE
.
character
string matching one entry in colorjam_steps()
,
which defines the sequence of Chroma and Luminance values across
the range of color hues.
numeric
hue to use for the first hue value in the
color sequence. This value represents the first color in the color
wheel defined by preset
, and colors are arrayed across 360 degrees.
numeric
alpha transparency of colors, values ranging from
0 to 1. If multiple values are supplied, they are applied in order to
the categorical colors returned.
numeric
optional vector with specific hues to use instead
of using Hstart
and filling the 360 degree color wheel with colors.
logical
(deprecated) formerly to enable or disable the
color warping for custom color wheel.
To disable a custom color wheel use preset="rgb"
.
numeric
(deprecated) in favor of argument preset
to
define the h1
and h2
values.
To use custom values for h1
and h2
use add_colorjam_preset()
to define a new preset name, then use the name with preset
.
numeric
(deprecated) in favor of argument step
to define the sequence of Chroma and Luminance values.
To define custom values, use add_colorjam_step()
to define a new
step name, then use the name with step
.
numeric
optional permitted ranges for
Chroma and Luminance values.
These adjustments may be useful to impose a darker or lighter
set of categorical colors.
When any Chroma value is outside the given Crange
, all color Chroma
values are scaled to fit this range using jamba::normScale()
.
This process scales the lowest observed Chroma to the minimum Crange,
and the highest observed Chroma to the maximum Crange, in order to
preserve intermediate gradient values.
When any Luminance value is outside the given Lrange
, all color
Luminance values are scaled to fit this range using jamba::normScale()
.
integer
starting step value to use from the sequence
of Chroma and Luminance values defined by colorjam_steps()
.
Default phase=1
begins with the first value; phase=2
begins
with the second value.
When phase
is negative, the Chroma and Luminance values are
each reversed, then the absolute value of phase
is used.
For example phase=-1
reverses the sequence, then uses the first value.
So it would begin with the last Chroma value, and the last Luminance
value.
character
value indicating the direction to travel
around the color wheel, permitting the color wheel to be reversed.
When using direction="-1"
it may also be helpful to use a negative
phase=-1
.
"1"
(default) travels forward, clockwise around the color wheel
"-1"
travels in reverse, counter-clockwise around the color wheel
logical
indicating whether to apply padding to
the end of the color hue sequence. This padding increases distinction
between the first and last colors.
numeric
value between 0 and 100, used when
do_hue_pad=TRUE
to apply a padding between the first and last color
hues.
character
string for the style of name assigned:
"none"
assigns no names
"n"
assigns names in numerical order
"closest_named_color"
assigns the closest matching color from
named_colors
, calling closest_named_color()
using ...
for
additional arguments.
"closestRcolor"
assigns names from closestRcolors()
, using ...
for additional arguments.
"hcl"
assigns names using H, C, L values
"color"
assigns names by hex color
logical
indicating whether to perform a visual test for
n
number of colors produced.
logical
whether to print verbose output
additional arguments are passed to
closest_named_color()
when nameStyle="closest_named_color"
closestRcolor()
when nameStyle="closestRcolor"
jamba::makeNames()
when nameStyle
is anything except "none"
.
character
vector of categorical colors
This function customizes similar functions grDevices::rainbow
,
colorspace::rainbow_hcl()
, and scales::hue_pal()
in two main
ways:
It uses the warped color wheel (see h2hw()
which compresses the
green component of the standard HCL color hue wheel, extending the yellow.
It uses a varying luminance and chroma vector which was selected to optimize visual distinctiveness of adjacent colors. There is still a limit to the maximum number of effectively different categorical colors, however this function appears to improve other available methods.
This function is also intended to enable use of a custom color wheel,
for example a set of color mappings could define color-blind friendly
ranges of colors when using the warped hue functions h2hw()
and
hw2h()
. When warpHue=TRUE
the values for h1
and
h2
are used to define a mapping from warped hues to standard
hues recognized by hcl()
.
Other colorjam core:
blend_colors()
,
closestRcolor()
,
closest_named_color()
,
color_complement()
,
colors_to_df()
,
group2colors()
,
sort_colors()
,
subset_colors()
rainbowJam(12);
#> [1] "#E8C421" "#B06C00" "#E6861C" "#D27058" "#FF8CA0" "#F56296" "#FFA4E7"
#> [8] "#9D63F8" "#A7A0FF" "#748FE9" "#76D0FF" "#00ACFE"
#> attr(,"preset")
#> [1] "dichromat2"
# show colors
jamba::showColors(rainbowJam(10));
# show colors
color_pie(rainbowJam(10));
# be fancy and label colors using the closest R named color
jamba::showColors(names(rainbowJam(6, nameStyle="closestRcolor")));
# comparison of version 0.0.19.900 and update with version 0.0.20.900
cat19 <- rainbowJam(n=12,
Cvals=c(140, 150, 160, 130, 200, 100),
Lvals=c( 47, 85, 62, 42, 77, 54))
#> Warning: ! `Cvals` and `Lvals` are deprecated, use argument `step`.
cat20 <- rainbowJam(n=12,
Cvals=c(200, 120, 160, 90, 180, 150),
Lvals=c( 44, 88, 74, 58, 80, 65))
#> Warning: ! `Cvals` and `Lvals` are deprecated, use argument `step`.
jamba::showColors(list(version19=cat19, version20=cat20))