color_funs | R Documentation |
Simple color creation with a wide variety of options (intensity, blending, lightening, darkening, opacity). This family of functions uses three-letter codes for common colors as follows.
color_funs()
color(x, lighten = 0, darken = 0, a = 1, comp = F)
rgba(r = 1, g = 1, b = 1, a = 1)
hsva(h = 1, s = 1, v = 1, a = 1)
blend(x, y, wx = 1, wy = 1, a = NA)
red(p = 1, s = 0, a = 1)
grn(p = 1, s = 0, a = 1)
blu(p = 1, s = 0, a = 1)
cyn(p = 1, s = 0, a = 1)
mag(p = 1, s = 0, a = 1)
vlt(p = 1, s = 0, a = 1)
ylw(p = 1, s = 0, a = 1)
gry(p = 0.5, a = 1)
blk(a = 1)
wht(a = 1)
ppl(p = 1, s = 0, a = 1)
orn(p = 1, s = 0, a = 1)
blu_grn(p = 1, s = 0, a = 1)
blu_ppl(p = 1, s = 0, a = 1)
blu_vlt(p = 1, s = 0, a = 1)
ylw_grn(p = 1, s = 0, a = 1)
ylw_orn(p = 1, s = 0, a = 1)
red_orn(p = 1, s = 0, a = 1)
red_ppl(p = 1, s = 0, a = 1)
red_vlt(p = 1, s = 0, a = 1)
pal_cb(ng, nc = min(ng, 20), a = 1)
pal_swatch(x)
x |
An atomic vec containing valid color representations. Recycled with |
lighten |
A complete proportion numeric vec of proportions by which to lighten the colors given in |
darken |
A complete proportion numeric vec of proportions by which to darken the colors given in |
a |
A complete proportion numeric vec of 1 or more alpha levels ( |
comp |
A complete logical vec indicating whether to return complementary colors. |
r , g , b |
Complete proportion numeric vecs giving intensities of red, blue, and green from the RGB color space. Recycled with each other and |
h , s , v |
Complete proportion numeric vecs giving hue, saturation, and value/brightness from the HSV color space. Recycled√with each other and |
y |
An atomic vec containing valid r color representations. |
wx , wy |
Complete non-negative numeric vecs giving weights to apply to |
p , s |
Complete poportion numeric vecs of 1 or more primary and secondary color intensities (respectively) in the range |
nc , ng |
Complete positive whole-number scalars giving the number of colors and groups, respectively. |
.na |
|
Color | Color | RGB channel values of |
code. | name | default color version |
wht | white | c(r = 1 , g = 1 , b = 1 ) |
blk | black | c(r = 0 , g = 0 , b = 0 ) |
gry | grey | c(r = 0.5, g = 0.5, b = 0.5) |
red | red | c(r = 1 , g = 0 , b = 0 ) |
grn | green | c(r = 0 , g = 1 , b = 0 ) |
blu | blue | c(r = 0 , g = 0 , b = 1 ) |
ylw | yellow | c(r = 1 , g = 1 , b = 0 ) |
cyn | cyan | c(r = 0 , g = 1 , b = 1 ) |
mag | magenta | c(r = 1 , g = 0 , b = 1 ) |
vlt | violet | c(r = 1 , g = 0 , b = 1 ) |
ppl | purple | a 1:2 blend of red:blue. |
orn | orange | a 33:51 blend of red:yellow. |
A character vector of 1
or more hexadecimal RGB + alpha color representations in the form '#RRGGBBAA'
.
color()
: Lighten, darken, set alpha opacity, and/or take the complement of a color argument.
rgba()
: Creates colors using proportional red, green, blue, and alpha channel values.
hsva()
: Creates colors using proportional hue, saturation, value, and alpha channel values.
blend()
: Blends colors x
and y
using weights wx
and wy
, and optionally adds proportional alpha opacity a
. NOTE that wx
and wy
are rescaled to sum to 1
.
red()
: Creates variations on red based on proportional weights p
, s
, and a
for primary color (red), secondary colors (green and blue), and alpha opacity, respectively.
grn()
: Creates variations on green based on proportional weights p
, s
, and a
for primary color (green), secondary colors (red and blue), and alpha opacity, respectively.
blu()
: Creates variations on blue based on proportional weights p
, s
, and a
for primary color (blue), secondary colors (red and green), and alpha opacity, respectively.
cyn()
: Creates variations on cyan based on proportional weights p
, s
, and a
for primary color (green and blue), secondary colors (red), and alpha opacity, respectively.
mag()
: Creates variations on magenta based on proportional weights p
, s
, and a
for primary color (red and blue), secondary colors (green), and alpha opacity, respectively.
vlt()
: Creates variations on violet based on proportional weights p
, s
, and a
for primary color (red and blue), secondary colors (green), and alpha opacity, respectively.
ylw()
: Creates variations on cyan based on proportional weights p
, s
, and a
for primary color (red and green), secondary colors (blue), and alpha opacity, respectively.
gry()
: Creates variations on grey based on proportional weights p
and a
for black and alpha opacity, respectively.
blk()
: Creates variations on black base on proportional weight a
for alpha opacity.
wht()
: Creates variations on white based on proportional weight a
for alpha opacity.
ppl()
: Creates variations on purple via blend(red(p, s), blu(p, s), 1, 2, a)
orn()
: Creates variations on orange via blend(red(p, s), ylw(p, s), 33, 51, a)
blu_grn()
: Creates variations on blue-green via blend(blu(p, s), grn(p, s), a)
.
blu_ppl()
: Creates variations on blue-purple via blend(blu(p, s), ppl(p, s), a)
.
blu_vlt()
: Creates variations on blue-violet via blend(blu(p, s), vlt(p, s), a)
.
ylw_grn()
: Creates variations on yellow-green via blend(ylw(p, s), grn(p, s), a)
.
ylw_orn()
: Creates variations on yellow-orange via blend(ylw(p, s), orn(p, s), a)
.
red_orn()
: Creates variations on red orange via blend(red(p, s), orange(p, s), a)
.
red_ppl()
: Creates variations on red-purple via blend(red(p, s), ppl(p, s), a)
.
red_vlt()
: Creates variations on red-violet via blend(red(p, s), vlt(p, s), a)
.
pal_cb()
: Generates a colorblind palette based on number of groups to be represented (ng
), number of colors to include (nc
) and alpha opacity values.
pal_swatch()
: Draws a swatch of the color palette in x
(a vector of character color values).
The only arguments not recycled are .na, nc
, and ng
.
p
and s
p
is used to indicate the proportion of the RGB values of the most intense version of a hue should be present in a resulting color. s
is used to indicate how much of complement of each RGB value should be present in a resulting color. The table below gives a helpful heuristic for setting values of p
and s
:
Argument values | Resulting color |
p = 1, s = 0 | intense |
p > s > 0 | lighter |
s < p < 1 | darker |
p = s = 1 | white |
p = s = 0 | black |
p = s = 0.5 | grey |
s = 1, p = 0 | intense, complementary |
s > p > 0 | lighter, complementary |
p < s < 1 | darker, complementary |
a concrete numeric example is that calling
ylw(p = 0.7, s = 0.3)
starts with primary and secondary RGB values of
prm = c(r = 1, g = 1, b = 0) sec = c(r = 0, g = 0, b = 1)
To get final RGB values, the primary RGB values are multiplied by p = 0.7
, secondary RGB values are multiple by s = 0.3
, and the results are summed pairwise giving
final = c(r = 0.7, g = 0.7, b = 0.3)
Other plots:
gg_help()
,
gr
,
markdown_help()
,
pals_help()
,
u2u_help()
color("red")
color("#00FF80")
color("#FF0000AA")
color(c("red", "#00FF80", "#FF0000AA"))
rgba(1/3, 2/3, 3/3, 1/2)
hsva(1/3, 2/3, 3/3, 1/2)
rgba(1/3, 2/3, 3/3, 1/2)
blend("red", "blue", wx = 2, wy = 1, a = 0.5)
blk(a = 1 / 2)
wht(a = 1 / 2)
gry(p = 2 /3, a = 0.5)
red(p = 2 / 3, s = 1 / 3, a = 1 / 2)
grn(p = 2 / 3, s = 1 / 3, a = 1 / 2)
blu(p = 2 / 3, s = 1 / 3, a = 1 / 2)
cyn(p = 2 / 3, s = 1 / 3, a = 1 / 2)
mag(p = 2 / 3, s = 1 / 3, a = 1 / 2)
vlt(p = 2 / 3, s = 1 / 3, a = 1 / 2)
ylw(p = 2 / 3, s = 1 / 3, a = 1 / 2)
ppl(p = 2 / 3, s = 1 / 3, a = 1 / 2)
orn(p = 2 / 3, s = 1 / 3, a = 1 / 2)
blu_grn(p = 2 / 3, s = 1 / 3, a = 1 / 2)
blu_ppl(p = 2 / 3, s = 1 / 3, a = 1 / 2)
blu_vlt(p = 2 / 3, s = 1 / 3, a = 1 / 2)
ylw_grn(p = 2 / 3, s = 1 / 3, a = 1 / 2)
ylw_orn(p = 2 / 3, s = 1 / 3, a = 1 / 2)
red_orn(p = 2 / 3, s = 1 / 3, a = 1 / 2)
red_ppl(p = 2 / 3, s = 1 / 3, a = 1 / 2)
red_vlt(p = 2 / 3, s = 1 / 3, a = 1 / 2)
pal_cb(12)
pal_cb(3)
pal_swatch(pal_cb(12))
pal_swatch(pal_cb(3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.