Create a Vector of Colors with specified Hue, Chroma and Luminance in R Programming – hcl() Function

hcl() function in R Language is used to create a vector of colors from vectors specifying hue, chroma and luminance.

Syntax: hcl(h, c, l)

Parameters:
h: The hue of the colour specified as an angle in the range [0, 360]. 0 yields red, 120 yields green 240 yields blue, etc.
c: The chroma of the colour. The upper bound for chroma depends on hue and luminance.
l: A value in the range [0, 100] giving the luminance of the colour.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# hcl function
  
# Calling the hcl() function
hcl(h = 10, c = 20, l = 30)
hcl(h = c(5, 10, 15), c = 20, l = 30)

chevron_right


Output:

[1] "#5E3E3F"
[1] "#5F3E42" "#5E3E3F" "#5E3F3D"

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# hcl function
  
# Calling the hcl() function
  
# Analogous Colors
# Good for those with red / green color confusion
hcl(h = seq(10, 50, by = 10))
  
# Metaphorical Colors
hcl(h = seq(10, 60, length = 4))
  
# Cool Colors
hcl(h = seq(120, 0, length = 4) + 150)
  
# Warm Colors
hcl(h = seq(120, 0, length = 4) - 30)

chevron_right


Output:

[1] "#FEC7C9" "#FCC8C1" "#F9CABB" "#F5CCB5" "#F0CFAF"
[1] "#FEC7C9" "#FACABD" "#F3CDB3" "#EAD1AB"
[1] "#D5D0FC" "#AFDAF5" "#99E1DF" "#A4E2C3"
[1] "#D4D8A7" "#F0CFAF" "#FEC7C9" "#FBC5E5"



My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.