hue: Get the hue of colors

View source: R/hue.R

hueR Documentation

Get the hue of colors

Description

Get the hues (angles around the color wheel, in [0,360]) of a vector of colors.

Usage

hue(x, model = "hsv", modulo = TRUE)

Arguments

x

vector of colors (specified as hex strings or named R colors), or numerical hues, or a mix thereof.

model

string defining the color model; valid models are the ones containing a hue component: hcl, lch, hsi, hsl, hsv.

modulo

logical, whether to restrict the hues in [0,360].

Value

A vector of hue angles, in [0,360] if modulo is TRUE.

See Also

channel used internally, to extract the hue channel.

Examples

# various input formats for x
hue(c("#F55D5B", "#16b2b4", "#6A9F16"))
hue(c("red", "green", "blue"))
hue(c(0, 10, 365))
hue(c(10, "#B55FFC", "pink", NA, 365))

# It is possible to reconstruct colors similar to the original ones
# based on the extracted hue, by providing the other components
cols <- c("firebrick", "gold", "limegreen", "dodgerblue",
          "navy", "mediumpurple")
show_col(cols,
  hsv(h=hue(cols, model="hsv"), s=0.9, v=1),
  hsl(h=hue(cols, model="hsl"), s=1, l=0.6),
  hcl(h=hue(cols, model="hcl"), c=1, l=0.8)
)
# = works, but is a bit less predictable with hcl().

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