hsv: HSV color specification

View source: R/parse_hsv.R

hsvR Documentation

HSV color specification

Description

Create a vector of colors from hue, saturation, and value.

Usage

hsv(h = 0, s = 0.6, v = 0.7, alpha = NULL, compat = FALSE)

Arguments

h

hue, either an angle around the color wheel, in [0,360] (angles outside of the range are rotated back to within [0, 360]: 380 = 20, -15 = 345, etc.), or a color (hex or named) from which the hue is extracted (by function hue).

s

saturation, number [0,1]; 0 is grey, 1 is full color.

v

value, number in [0,1]; 0 is black, 1 is full brightness

alpha

transparency, number in [0,1]; 0 means fully transparent, 1 means fully opaque. See function alpha for another way to change the transparency after the fact.

compat

whether to make the conventions compatible with the built-in function grDevices::hsv: h should be in [0,1], not [0,360].

Details

The first argument can also be a data.frame or a matrix. In that case, its columns are considered as the color components, taken in order, and the other color components arguments are ignored.

When separate arguments are used for the color components and are vectors, values in shorter arguments are recycled to match the length of the longest argument. If the lengths are not compatible, an error is output.

The HSV color model tentatively separates color (hue), color intensity (saturation), and color lightness (value), which helps with the creation of color palettes compared to RGB. However, while the color components are separated numerically, some confusion remains in the way colors are perceived by the human eye/brain. Indeed, even at constant s and v some hues are perceived as brighter (yellow and green for example) and therefore draw the viewer's attention. This is one of the common problems with 'rainbow'-like color scales (which are constructed in HSL or HSV space). See the function luminance for a numerical demonstration. For the creation of color palettes, the HCL space (function hcl) should be preferred.

Value

A vector of colors specified as hex codes

See Also

parse_color for the general function to parse colors in various specifications (which this function calls internally) and convert_color to convert parsed colors to another model.

Other color specifications: cmyk(), css(), hcl(), hex(), hsi(), hsl(), lab(), parse_color(), rgb(), ryb(), temperature(), wavelength()

Examples

hsv()
hsv(330, 1, 0.6)
hsv(data.frame(c(330, 340), c(1,1), c(0.6, 0.4)))
hsv(matrix(c(330, 340, 1, 1, 0.6, 0.4), ncol=3))
hsv(c(330, 340), 1, 0.6)

# Color ramps
ramp <- seq(0, 1, length.out=10)
show_col(hsv(h=ramp*360), hsv(s=ramp), hsv(v=ramp))

# Recreate the rainbow() scale
show_col(hsv(h=seq(0, 324, length.out=10), s=1, v=1), rainbow(10))

jiho/chroma documentation built on Nov. 26, 2022, 2:39 a.m.