color2gradient | R Documentation |
Make a color gradient
color2gradient(
col,
n = NULL,
gradientWtFactor = NULL,
dex = 1,
reverseGradient = TRUE,
verbose = FALSE,
...
)
col |
some type of recognized R color input as:
|
n |
|
gradientWtFactor |
|
dex |
|
reverseGradient |
|
verbose |
|
... |
other parameters are ignored. |
This function converts a single color into a color gradient by expanding the initial color into lighter and darker colors around the central color. The amount of gradient expansion is controlled by gradientWtFactor, which is a weight factor scaled to the maximum available range of bright to dark colors.
As an extension, the function can take a vector of colors, and expand each
into its own color gradient, each with its own number of colors.
If a vector with supplied that contains repeated colors, these colors
are expanded in-place into a gradient, bypassing the value for n
.
If a list is supplied, a list is returned of the same length, where
each vector inside the list is a color gradient of length specified
by n
. If the input list contains multiple values, only the first
color is used to define the color gradient.
Other jam color functions:
alpha2col()
,
applyCLrange()
,
col2alpha()
,
col2hcl()
,
col2hsl()
,
col2hsv()
,
fixYellowHue()
,
fixYellow()
,
getColorRamp()
,
hcl2col()
,
hsl2col()
,
hsv2col()
,
isColor()
,
kable_coloring()
,
makeColorDarker()
,
make_html_styles()
,
make_styles()
,
rgb2col()
,
setCLranges()
,
setTextContrastColor()
,
showColors()
,
unalpha()
,
warpRamp()
# given a list, it returns a list
x <- color2gradient(list(Reds=c("red"), Blues=c("blue")), n=c(4,7));
showColors(x);
# given a vector, it returns a vector
xv <- color2gradient(c(red="red", blue="blue"), n=c(4,7));
showColors(xv);
# Expand colors in place
# This process is similar to color jittering
colors1 <- c("red","blue")[c(1,1,2,2,1,2,1,1)];
names(colors1) <- colors1;
colors2 <- color2gradient(colors1);
showColors(list(`Input colors`=colors1, `Output colors`=colors2));
# You can do the same using a list intermediate
colors1L <- split(colors1, colors1);
showColors(colors1L);
colors2L <- color2gradient(colors1L);
showColors(colors2L);
# comparison of fixed gradientWtFactor with dynamic gradientWtFactor
showColors(list(
`dynamic\ngradientWtFactor\ndex=1`=color2gradient(
c("yellow", "navy", "firebrick", "orange"),
n=3,
gradientWtFactor=NULL,
dex=1),
`dynamic\ngradientWtFactor\ndex=2`=color2gradient(
c("yellow", "navy", "firebrick", "orange"),
n=3,
gradientWtFactor=NULL,
dex=2),
`fixed\ngradientWtFactor=2/3`=color2gradient(
c("yellow", "navy", "firebrick", "orange"),
n=3,
gradientWtFactor=2/3,
dex=1)
))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.