Skip to contents

Extract the hue, chroma, or luminance color components from a vector of colors.

Usage

clr_extract_chroma(col)

Arguments

col

A colors object (see color()) or a vector of any of the three kinds of R color specifications, i.e., either a color name (as listed by grDevices::colors()), a hexadecimal string (see col2rgb()), or a positive integer i meaning grDevices::palette()[i].

Value

Numeric vector of values.

Details

The range of the value are:

  • Hue is ranging from 0 to 360.

  • Luminance is ranging from 0 to 100.

  • Chroma, while dependent on hue and luminance, will roughly be within 0 and 180.

Use clr_extract() if you are planning to extraction multiple components.

See also

Other Extraction: clr_extract(), clr_extract_hue(), extract_rgba()

Examples

clr_extract_hue(rainbow(100), "HCL")
#>   [1]  12.1743993  12.5306739  13.2019367  14.2401608  15.7433194  17.9398231
#>   [7]  20.6366468  24.0325037  28.2018637  33.5589531  39.4333571  46.0453955
#>  [13]  53.6927827  61.1129483  68.4353786  75.3605222  82.0763087  87.6722317
#>  [19]  92.9618832  98.2908700 102.9003017 107.0798367 111.0376255 114.2794484
#>  [25] 117.0851150 119.4813276 121.6212408 123.2717117 124.6104447 125.7287706
#>  [31] 126.5169189 127.0810239 127.4664561 127.6638177 127.8276701 128.0922246
#>  [37] 128.5275857 129.1794009 130.0854409 131.3825914 132.9672551 134.9801182
#>  [43] 137.6995986 140.9043822 144.8840847 150.1628571 156.2513143 163.5609312
#>  [49] 172.0772023 182.2152662 192.1722280 202.4574741 213.6022041 223.4263658
#>  [55] 232.1003165 239.8531264 245.7609401 250.5190622 254.3191292 257.5141705
#>  [61] 259.8583403 261.6900809 263.1798354 264.2150184 264.9569153 265.4762446
#>  [67] 265.7508695 265.9363269 266.1594999 266.5946828 267.2300189 268.1144990
#>  [73] 269.3630201 270.8473859 272.6617323 274.9877940 277.5565139 280.5153102
#>  [79] 283.8682749 287.8672275 291.9807845 296.3939251 301.3474111 306.1242680
#>  [85] 311.0483286 316.4420366 322.6530408 328.7538820 334.9253503 341.3417484
#>  [91] 346.9882915 352.1195501 356.9195422   0.7492825   3.9365096   6.6657608
#>  [97]   8.6462991  10.1224166  11.1502985  11.8185455
clr_extract_chroma(rainbow(100))
#>   [1] 179.04898 177.11377 173.61318 168.54536 161.87166 153.31956 144.40822
#>   [8] 135.14274 126.04672 117.10258 109.91317 104.26925 100.25084  98.48728
#>  [15]  98.62633 100.49717 104.11255 106.86739 106.90138 107.88981 109.55103
#>  [22] 111.75435 114.51407 117.31846 120.18789 123.00019 125.82357 128.22168
#>  [29] 130.31983 132.18502 133.56456 134.58644 135.30174 135.67349 135.35722
#>  [36] 134.35401 132.74150 130.41295 127.33682 123.23163 118.64503 113.41334
#>  [43] 107.24230 101.06279  94.70899  88.03803  82.23807  77.29365  73.66168
#>  [50]  71.73209  72.08567  70.90941  72.31466  76.06311  81.81303  89.55934
#>  [57]  97.70330 106.08191 114.10870 121.66863 127.32690 131.27795 133.51325
#>  [64] 133.96596 133.31913 132.13917 131.19271 130.75232 131.00730 131.46454
#>  [71] 132.04551 132.70494 133.39123 133.91652 134.24574 134.33166 134.16891
#>  [78] 133.83095 133.42781 133.09667 133.06697 133.49938 134.66666 136.57595
#>  [85] 134.22695 130.40553 127.79542 126.90263 127.60602 130.08879 133.88359
#>  [92] 138.83028 144.98573 151.16773 157.34293 163.51023 168.57453 172.71353
#>  [99] 175.79778 177.89830
clr_extract_luminance(rainbow(100))
#>   [1] 53.24079 53.60957 54.28831 55.29940 56.68807 58.57857 60.71191 63.16228
#>   [9] 65.89278 69.07098 72.26072 75.61941 79.35472 82.97263 86.68063 90.46051
#>  [17] 94.55457 96.75739 95.65703 94.55998 93.60533 92.72372 91.86516 91.13774
#>  [25] 90.48561 89.90853 89.37479 88.94964 88.59520 88.29194 88.07403 87.91582
#>  [33] 87.80661 87.75033 87.74531 87.77076 87.81205 87.87254 87.95415 88.06626
#>  [41] 88.19634 88.35183 88.54686 88.75804 88.99741 89.28457 89.58419 89.91367
#>  [49] 90.27335 90.69053 91.11322 86.76756 82.12286 77.76587 73.41459 68.79193
#>  [57] 64.49163 60.24473 56.07922 51.76843 47.90478 44.28084 40.77353 37.92425
#>  [65] 35.60273 33.80044 32.77642 32.36890 32.62660 33.11981 33.81896 34.75429
#>  [73] 36.00730 37.40776 39.00771 40.90976 42.85222 44.92634 47.11166 49.54462
#>  [81] 51.90416 54.32571 56.96391 59.47859 59.75985 58.95441 58.15139 57.45286
#>  [89] 56.80824 56.18125 55.65103 55.17687 54.73281 54.37378 54.06913 53.80232
#>  [97] 53.60440 53.45413 53.34795 53.27819