Title: | Color Manipulation Tools |
---|---|
Description: | Manipulate and visualize colors in a intuitive, low-dependency and functional way. |
Authors: | Emil Hvitfeldt [aut, cre] |
Maintainer: | Emil Hvitfeldt <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.2.9000 |
Built: | 2024-09-07 04:50:23 UTC |
Source: | https://github.com/emilhvitfeldt/prismatic |
Finds the color in 'y' with the highest contrast to the color 'x'.
best_contrast(x, y = c("#010101", "#FFFFFF"))
best_contrast(x, y = c("#010101", "#FFFFFF"))
x |
Multiple colors |
y |
Multiple colors |
The elements of 'y' with highest contrast to 'x'.
best_contrast("red") best_contrast("grey20") best_contrast("white") best_contrast(rainbow(10), rainbow(3))
best_contrast("red") best_contrast("grey20") best_contrast("white") best_contrast(rainbow(10), rainbow(3))
Visualize color vision deficiency
check_color_blindness(col)
check_color_blindness(col)
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. This function will showcase the effect of all 3 kinds of color vision deficiency at the same time side by side. |
Nothing
check_color_blindness(rainbow(10)) check_color_blindness(terrain.colors(10))
check_color_blindness(rainbow(10)) check_color_blindness(terrain.colors(10))
Sets alpha in color
clr_alpha(col, alpha = 0.5)
clr_alpha(col, alpha = 0.5)
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
alpha |
Numeric between 0 and 1. 0 will result in full transparency and 1 results in no transparency. |
a colors object
plot(clr_alpha(rainbow(10), 0.5)) plot(clr_alpha(rainbow(10), 0.2)) plot(clr_alpha(rainbow(10), seq(0, 1, length.out = 10)))
plot(clr_alpha(rainbow(10), 0.5)) plot(clr_alpha(rainbow(10), 0.2)) plot(clr_alpha(rainbow(10), seq(0, 1, length.out = 10)))
Make a color more dark
clr_darken(col, shift = 0.5, space = c("HCL", "HSL", "combined"))
clr_darken(col, shift = 0.5, space = c("HCL", "HSL", "combined"))
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
shift |
Numeric between 0 and 1, 0 will do zero darkening, 1 will do complete darkening turning the color to black. Defaults to 0.5. |
space |
character string specifying the color space in which adjustment happens. Can be either "HCL", "HSL" or "combined". Defaults to "HCL". |
The colors will be transformed to HSL color space (hue, saturation,
lightness) where the lightness of the color will be modified. The lightness
of a color takes a value between 0 and 1, with 0 being black and 1 being
white. The shift
argument takes a value between 0 and 1, where 0
means that the lightness stays unchanged and 1 means completely black. As an
example, if the lightness of the color is 0.6 and shift is 0.5, then the
lightness be set to the halfway point between 0.6 and 0, which is 0.3.
If space = "HSL" then the colors are transformed to HSL space where the lightness value L is adjusted. If space = "HCL" then the colors are transformed to Cylindrical HCL space where the luminance value L is adjusted. If space = "combined" then the colors are transformed into HSL and Cylindrical HCL space. Where the color adjusting is happening HLS is copied to the values in the HCL transformation. Thus the "combined" transformation adjusts the luminance in HCL space and chroma in HSL space. For more information regarding use of color spaces, please refer to the colorspace paper https://arxiv.org/abs/1903.06490.
a color object of same length as col.
https://en.wikipedia.org/wiki/HSL_and_HSV
https://en.wikipedia.org/wiki/CIELUV
https://arxiv.org/abs/1903.06490
clr_lighten
# Using linear shift plot(clr_darken(rep("red", 11), shift = seq(0, 1, 0.1))) plot(clr_darken(rep("red", 11), shift = seq(0, 1, 0.1), space = "HSL")) plot(clr_darken(rep("red", 11), shift = seq(0, 1, 0.1), space = "combined")) plot(clr_darken(terrain.colors(10))) # Using exponential shifts plot(clr_darken(rep("red", 11), shift = log(seq(1, exp(1), length.out = 11))))
# Using linear shift plot(clr_darken(rep("red", 11), shift = seq(0, 1, 0.1))) plot(clr_darken(rep("red", 11), shift = seq(0, 1, 0.1), space = "HSL")) plot(clr_darken(rep("red", 11), shift = seq(0, 1, 0.1), space = "combined")) plot(clr_darken(terrain.colors(10))) # Using exponential shifts plot(clr_darken(rep("red", 11), shift = log(seq(1, exp(1), length.out = 11))))
Make a color more desaturated
clr_desaturate(col, shift = 0.5)
clr_desaturate(col, shift = 0.5)
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
shift |
Numeric between 0 and 1, 0 will do zero desaturation, 1 will do complete desaturation. Defaults to 0.5. |
The colors will be transformed to HSL color space (hue, saturation,
lightness) where the saturation of the color will be modified. The
saturation of a color takes a value between 0 and 1, with 0 being black and
1 being white. The shift
argument takes a value between 0 and 1,
where 0 means that the saturation stays unchanged and 1 means completely
desaturated. As an example, if the saturation of the color is 0.6 and shift
is 0.5, then the saturation be set to the halfway point between 0.6 and 0
which is 0.3.
a colors object of same length as col.
https://en.wikipedia.org/wiki/HSL_and_HSV
clr_saturate
plot(clr_desaturate(terrain.colors(10), shift = 0.5)) plot(clr_desaturate(terrain.colors(10), shift = 0.9)) plot(clr_desaturate(rep("firebrick", 11), shift = seq(0, 1, 0.1)))
plot(clr_desaturate(terrain.colors(10), shift = 0.5)) plot(clr_desaturate(terrain.colors(10), shift = 0.9)) plot(clr_desaturate(rep("firebrick", 11), shift = seq(0, 1, 0.1)))
Extract multiple color components at the same time.
clr_extract( col, components = c("red", "green", "blue", "hue_hsl", "saturation", "lightness", "hue_hcl", "chroma", "luminance") )
clr_extract( col, components = c("red", "green", "blue", "hue_hsl", "saturation", "lightness", "hue_hcl", "chroma", "luminance") )
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
components |
character, components that should be extracted. See details for allowed components. |
The allowed values for 'components' are
- red - green - blue - hue_hsl - saturation - lightness - hue_hcl - chroma - luminance
This function is to be preferred if you need to extract multiple components at the same time, since it doesn't need repeat transformations.
data.frame of components
Other Extraction:
clr_extract_chroma()
,
clr_extract_hue()
,
clr_extract_red()
clr_extract(rainbow(10)) clr_extract(rainbow(10), c("hue_hsl", "saturation"))
clr_extract(rainbow(10)) clr_extract(rainbow(10), c("hue_hsl", "saturation"))
Extract the hue, chroma, or luminance color components from a vector of colors.
clr_extract_chroma(col)
clr_extract_chroma(col)
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
The range of the value are
- hue ranges from 0 to 360 - luminance ranges from 0 to 100 - chroma while depended on hue and luminance will roughly be within 0 and 180
Use [clr_extract()] if you are planning to extraction multiple components.
Numeric vector of values.
Other Extraction:
clr_extract()
,
clr_extract_hue()
,
clr_extract_red()
clr_extract_hue(rainbow(100), "HCL") clr_extract_chroma(rainbow(100)) clr_extract_luminance(rainbow(100))
clr_extract_hue(rainbow(100), "HCL") clr_extract_chroma(rainbow(100)) clr_extract_luminance(rainbow(100))
Extract the hue, saturation, or lightness color components from a vector of colors.
clr_extract_hue(col, space = c("HSL", "HCL")) clr_extract_saturation(col) clr_extract_lightness(col) clr_extract_luminance(col)
clr_extract_hue(col, space = c("HSL", "HCL")) clr_extract_saturation(col) clr_extract_lightness(col) clr_extract_luminance(col)
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
space |
character string specifying the color space where hue is extracted from. Can be either "HCL" or "HSL". |
The range of the value are
- hue ranges from 0 to 360. in a circular fashion such that 0 and 360 are near identical. 0 is red - saturation ranges from 0 to 100. 100 is full saturation, 0 is no saturation - lightness ranges from 0 to 100. 100 is full lightness, 0 is no lightness
Use [clr_extract()] if you are planning to extraction multiple components.
Numeric vector of values.
Other Extraction:
clr_extract()
,
clr_extract_chroma()
,
clr_extract_red()
clr_extract_hue(rainbow(100), "HSL") clr_extract_saturation(rainbow(100)) clr_extract_lightness(rainbow(100))
clr_extract_hue(rainbow(100), "HSL") clr_extract_saturation(rainbow(100)) clr_extract_lightness(rainbow(100))
Extract the red, green, or blue color components from a vector of colors.
clr_extract_red(col) clr_extract_green(col) clr_extract_blue(col) clr_extract_alpha(col)
clr_extract_red(col) clr_extract_green(col) clr_extract_blue(col) clr_extract_alpha(col)
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
The values of the output will range between 0 and 255.
Use [clr_extract()] if you are planning to extraction multiple components.
Numeric vector of values.
Other Extraction:
clr_extract()
,
clr_extract_chroma()
,
clr_extract_hue()
clr_extract_red(rainbow(100)) clr_extract_green(rainbow(100)) clr_extract_blue(rainbow(100)) clr_extract_alpha(rainbow(100))
clr_extract_red(rainbow(100)) clr_extract_green(rainbow(100)) clr_extract_blue(rainbow(100)) clr_extract_alpha(rainbow(100))
This function has a selection of different methods to turn colors into grayscale.
clr_grayscale( col, method = c("luma", "averaging", "min_decomp", "max_decomp", "red_channel", "green_channel", "blue_channel") ) clr_greyscale( col, method = c("luma", "averaging", "min_decomp", "max_decomp", "red_channel", "green_channel", "blue_channel") )
clr_grayscale( col, method = c("luma", "averaging", "min_decomp", "max_decomp", "red_channel", "green_channel", "blue_channel") ) clr_greyscale( col, method = c("luma", "averaging", "min_decomp", "max_decomp", "red_channel", "green_channel", "blue_channel") )
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
method |
character string specifying the grayscaling method. Can be one of "luma", "averaging", "min_decomp", "max_decomp", "red_channel", "green_channel" and "blue_channel". Defaults to "luma". |
if method = "averaging" then the red, green and blue have been averaged together to create the grey value. This method does a poor job of representing the way the human eye sees color. If method = "luma" (the default) then then a weighted average is used to calculate the grayscale values. The BT. 709 method from the ITU Radiocommunication Sector have determined the weights. It method = "min_decomp" or method = "max_decomp", then a decomposition method is used where the minimum or maximum color value have been selected for the color value. So the color rgb(60, 120, 40) would have the min_decomp value of 40 and max_decomp value of 120. If method is "red_channel", "green_channel" or "blue_channel", then the corresponding color channel been selected for the values of grayscale.
a colors object of same length as col.
https://tannerhelland.com/3643/grayscale-image-algorithm-vb6/
https://en.wikipedia.org/wiki/Luma
plot(clr_grayscale(rainbow(10))) plot(clr_grayscale(terrain.colors(10))) viridis_colors <- c( "#4B0055FF", "#422C70FF", "#185086FF", "#007094FF", "#008E98FF", "#00A890FF", "#00BE7DFF", "#6CD05EFF", "#BBDD38FF", "#FDE333FF" ) plot(clr_grayscale(viridis_colors, method = "luma")) plot(clr_grayscale(viridis_colors, method = "averaging")) plot(clr_grayscale(viridis_colors, method = "min_decomp")) plot(clr_grayscale(viridis_colors, method = "max_decomp")) plot(clr_grayscale(viridis_colors, method = "red_channel")) plot(clr_grayscale(viridis_colors, method = "green_channel")) plot(clr_grayscale(viridis_colors, method = "blue_channel"))
plot(clr_grayscale(rainbow(10))) plot(clr_grayscale(terrain.colors(10))) viridis_colors <- c( "#4B0055FF", "#422C70FF", "#185086FF", "#007094FF", "#008E98FF", "#00A890FF", "#00BE7DFF", "#6CD05EFF", "#BBDD38FF", "#FDE333FF" ) plot(clr_grayscale(viridis_colors, method = "luma")) plot(clr_grayscale(viridis_colors, method = "averaging")) plot(clr_grayscale(viridis_colors, method = "min_decomp")) plot(clr_grayscale(viridis_colors, method = "max_decomp")) plot(clr_grayscale(viridis_colors, method = "red_channel")) plot(clr_grayscale(viridis_colors, method = "green_channel")) plot(clr_grayscale(viridis_colors, method = "blue_channel"))
Make a color more light
clr_lighten(col, shift = 0.5, space = c("HCL", "HSL", "combined"))
clr_lighten(col, shift = 0.5, space = c("HCL", "HSL", "combined"))
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
shift |
Numeric between 0 and 1, 0 will do zero lightening, 1 will do complete lightening turning the color to white. Defaults to 0.5. |
space |
character string specifying the color space in which adjustment happens. Can be either "HCL", "HSL" or "combined". Defaults to "HCL". |
The colors will be transformed to HSL color space (hue, saturation,
lightness) where the lightness of the color will be modified. The lightness
of a color takes a value between 0 and 1, with 0 being black and 1 being
white. The shift
argument takes a value between 0 and 1, where 0
means that the lightness stays unchanged and 1 means completely white. As an
example, if the lightness of the color is 0.6 and shift is 0.5, then the
lightness be set to the halfway point between 0.6 and 1 which is 0.8.
If space = "HSL" then the colors are transformed to HSL space where the lightness value L is adjusted. If space = "HCL" then the colors are transformed to Cylindrical HCL space where the luminance value L is adjusted. If space = "combined" then the colors are transformed into HSL and Cylindrical HCL space. Where the color adjusting is happening HLS is copied to the values in the HCL transformation. Thus the "combined" transformation adjusts the luminance in HCL space and chroma in HSL space. For more information regarding use of color spaces, please refer to the colorspace paper https://arxiv.org/abs/1903.06490.
a colors object of same length as col.
https://en.wikipedia.org/wiki/HSL_and_HSV
https://en.wikipedia.org/wiki/CIELUV
https://arxiv.org/abs/1903.06490
clr_darken
# Using linear shift plot(clr_lighten(rep("red", 11), shift = seq(0, 1, 0.1))) plot(clr_lighten(rep("red", 11), shift = seq(0, 1, 0.1), space = "HSL")) plot(clr_lighten(rep("red", 11), shift = seq(0, 1, 0.1), space = "combined")) plot(clr_lighten(terrain.colors(10))) # Using exponential shifts plot(clr_lighten(rep("red", 11), shift = log(seq(1, exp(1), length.out = 11))))
# Using linear shift plot(clr_lighten(rep("red", 11), shift = seq(0, 1, 0.1))) plot(clr_lighten(rep("red", 11), shift = seq(0, 1, 0.1), space = "HSL")) plot(clr_lighten(rep("red", 11), shift = seq(0, 1, 0.1), space = "combined")) plot(clr_lighten(terrain.colors(10))) # Using exponential shifts plot(clr_lighten(rep("red", 11), shift = log(seq(1, exp(1), length.out = 11))))
Mixes a color into
clr_mix(col, mix_in, ratio = 0.5)
clr_mix(col, mix_in, ratio = 0.5)
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
mix_in |
A single color any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
ratio |
Numeric between 0 and 1. 0 will result on no mixing. 1 results in all the colors turning to mix_in. Must be of length 1 or same length as col. |
a colors object
plot(clr_mix(rainbow(10), "blue")) plot(clr_mix(rainbow(10), "red")) plot(clr_mix(rainbow(10), "#5500EE")) plot(clr_mix(rainbow(10), "black", seq(1, 0, length.out = 10)))
plot(clr_mix(rainbow(10), "blue")) plot(clr_mix(rainbow(10), "red")) plot(clr_mix(rainbow(10), "#5500EE")) plot(clr_mix(rainbow(10), "black", seq(1, 0, length.out = 10)))
Negates colors in RGB space
clr_negate(col)
clr_negate(col)
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
The negation of color is happening in the red-green-blue colorspace RGB. Meaning that if we take the specification for Orange which is rgb(255, 165, 0), then we negate by taking the oppesite number on the scale from 0 to 255, leaving us with rgb(0, 90, 255) which is a shade of blue.
a colors object of same length as col.
terr <- color(terrain.colors(10)) terr clr_negate(terr) plot(terr) plot(clr_negate(terr))
terr <- color(terrain.colors(10)) terr clr_negate(terr) plot(terr) plot(clr_negate(terr))
Simulate color vision deficiency
clr_protan(col, severity = 1) clr_deutan(col, severity = 1) clr_tritan(col, severity = 1)
clr_protan(col, severity = 1) clr_deutan(col, severity = 1) clr_tritan(col, severity = 1)
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
severity |
A numeric, Severity of the color vision defect, a number between 0 and 1. 0 means no deficiency, 1 means complete deficiency. Defaults to 1. |
The matrices uses to perform transformations have been taken as the 1.0 value in table 1 in http://www.inf.ufrgs.br/~oliveira/pubs_files/CVD_Simulation/CVD_Simulation.html.
a colors object of same length as col.
http://www.inf.ufrgs.br/~oliveira/pubs_files/CVD_Simulation/CVD_Simulation.html
Gustavo M. Machado, Manuel M. Oliveira, and Leandro A. F. Fernandes "A Physiologically-based Model for Simulation of Color Vision Deficiency". IEEE Transactions on Visualization and Computer Graphics. Volume 15 (2009), Number 6, November/December 2009. pp. 1291-1298.
rainbow_colors <- color(rainbow(10)) plot(clr_protan(rainbow_colors)) plot(clr_deutan(rainbow_colors)) plot(clr_tritan(rainbow_colors)) viridis_colors <- c( "#4B0055FF", "#422C70FF", "#185086FF", "#007094FF", "#008E98FF", "#00A890FF", "#00BE7DFF", "#6CD05EFF", "#BBDD38FF", "#FDE333FF" ) plot(clr_protan(viridis_colors)) plot(clr_deutan(viridis_colors)) plot(clr_tritan(viridis_colors))
rainbow_colors <- color(rainbow(10)) plot(clr_protan(rainbow_colors)) plot(clr_deutan(rainbow_colors)) plot(clr_tritan(rainbow_colors)) viridis_colors <- c( "#4B0055FF", "#422C70FF", "#185086FF", "#007094FF", "#008E98FF", "#00A890FF", "#00BE7DFF", "#6CD05EFF", "#BBDD38FF", "#FDE333FF" ) plot(clr_protan(viridis_colors)) plot(clr_deutan(viridis_colors)) plot(clr_tritan(viridis_colors))
Rotate the colors around the hue wheel
clr_rotate(col, degrees = 0)
clr_rotate(col, degrees = 0)
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
degrees |
Numeric between 0 and 360, denoting the amount of degrees the colors should be rotated. Defaults to 0. |
The colors will be transformed to HCL color space (Hue-Chroma-Luminance) where the hue of the color will be rotation.
a colors object of same length as col.
https://en.wikipedia.org/wiki/HCL_color_space
plot(clr_rotate(terrain.colors(10))) plot(clr_rotate(terrain.colors(10), degrees = 90)) plot(clr_rotate(terrain.colors(10), degrees = 180)) plot(clr_rotate(rep("magenta", 11), degrees = seq(0, 360, length.out = 11)))
plot(clr_rotate(terrain.colors(10))) plot(clr_rotate(terrain.colors(10), degrees = 90)) plot(clr_rotate(terrain.colors(10), degrees = 180)) plot(clr_rotate(rep("magenta", 11), degrees = seq(0, 360, length.out = 11)))
Make a color more saturated
clr_saturate(col, shift = 0.5)
clr_saturate(col, shift = 0.5)
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
shift |
Numeric between 0 and 1, 0 will do zero saturation, 1 will do complete saturation. Defaults to 0.5. |
The colors will be transformed to HSL color space (hue, saturation,
lightness) where the saturation of the color will be modified.
The saturation of a color takes a value between 0 and 1, with 0 being black
and 1 being white. The shift
argument takes a value between 0 and 1,
where 0 means that the saturation stays unchanged and 1 means completely
saturated. As an example, if the saturation of the color is 0.6 and shift is
0.5, then the saturation be set to the halfway point between 0.6 and 1 which
is 0.8.
a color object of same length as col.
https://en.wikipedia.org/wiki/HSL_and_HSV
clr_desaturate
plot(clr_saturate(terrain.colors(10), shift = 0.5)) plot(clr_saturate(terrain.colors(10), shift = 1)) plot(clr_saturate(rep("firebrick", 11), shift = seq(0, 1, 0.1)))
plot(clr_saturate(terrain.colors(10), shift = 0.5)) plot(clr_saturate(terrain.colors(10), shift = 1)) plot(clr_saturate(rep("firebrick", 11), shift = seq(0, 1, 0.1)))
Turn vector to color vector
color(col) colour(col)
color(col) colour(col)
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
Alpha values will be automatically added to hexcodes. If none at present it will default to no alpha (FF).
a colors object.
terrain_10 <- color(terrain.colors(10)) terrain_10[1:4] plot(terrain_10) plot(terrain_10, labels = TRUE) grey_10 <- color(gray.colors(10, start = 0, end = 1)) grey_10 plot(grey_10, labels = TRUE)
terrain_10 <- color(terrain.colors(10)) terrain_10[1:4] plot(terrain_10) plot(terrain_10, labels = TRUE) grey_10 <- color(gray.colors(10, start = 0, end = 1)) grey_10 plot(grey_10, labels = TRUE)
Calculates the contrast ratio between 'x' and the colors 'y'. Contrast ratios can range from 1 to 21 with 1 being no contrast (same color) and 21 being highest contrast.
contrast_ratio(x, y)
contrast_ratio(x, y)
x |
A color object or vector of length 1 of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
y |
A color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
The formula for calculating contract ratio is
where
L1 is the relative luminance of the lighter of the colors, and
L2 is the relative luminance of the darker of the colors.
Relative luminance is calculated according to https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef.
The elements of 'y' with highest contrast to 'x'.
https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html
contrast_ratio("red", "blue") contrast_ratio("grey20", grey.colors(10)) contrast_ratio("white", c("white", "black"))
contrast_ratio("red", "blue") contrast_ratio("grey20", grey.colors(10)) contrast_ratio("white", c("white", "black"))
Test if the object is a color
is_color(x)
is_color(x)
x |
An object |
TRUE if the object inherits from the color class.
This function lets you modify individual axes of a color in HCL color space.
modify_hcl(col, h, c, l)
modify_hcl(col, h, c, l)
col |
a color object or vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by colors()), a hexadecimal string of the form "#rrggbb" or "#rrggbbaa" (see rgb), or a positive integer i meaning palette()[i]. |
h |
Expression to modify the hue of 'col' |
c |
Expression to modify the chroma of 'col' |
l |
Expression to modify the luminance of 'col' |
The expression used in 'h', 'c', and 'l' is evaluated in the 'hcl' space and and you have access to 'h', 'c', and 'l' as vectors along with vectors in the calling environment.
'h' ranges from 0 to 360, 'l' ranges from 0 to 100, and 'c' while depended on 'h' and 'l' will roughly be within 0 and 180, but often on a narrower range. Colors after modification will be adjusted to fit within the color space.
a colors object.
https://en.wikipedia.org/wiki/HCL_color_space
plot(modify_hcl("red", h = 160)) plot(modify_hcl("red", h = h + 50)) plot(modify_hcl("red", h = h + 1:100)) plot(modify_hcl("red", c = c - 1:200)) plot(modify_hcl("red", l = l + 1:50)) plot(modify_hcl(rainbow(10), l = 25)) plot(modify_hcl(rainbow(10), h + h / 2, l = 70))
plot(modify_hcl("red", h = 160)) plot(modify_hcl("red", h = h + 50)) plot(modify_hcl("red", h = h + 1:100)) plot(modify_hcl("red", c = c - 1:200)) plot(modify_hcl("red", l = l + 1:50)) plot(modify_hcl(rainbow(10), l = 25)) plot(modify_hcl(rainbow(10), h + h / 2, l = 70))