These functions help you consider colors in terms of their hue, chroma, and luminance (HCL). You will need the colorspace package to run these functions.

hcl_dataframe(colors, background = NULL)

hcl_table(colors, background = NULL, title = NULL, decimals = 1)

Arguments

colors

character vector of R colors. Can be hex codes, etc. Names can be meaningful.

background

character R color to use as background; used for prominence calculation.

title

character title for table.

decimals

numeric number of decimal places for values in table.

Value

hcl_dataframe()

data.frame with columns: name, color, hue, chroma luminance, prominence.

hcl_table()

An object with S3 class gt_tbl.

Details

If you provide a background color, the prominence of each color from the background, i.e. the perceptual distance from the background, is calculated. Furthermore, hcl_table() sets the background color accordingly.

  • hcl_dataframe(): get a data frame with HCL data

  • hcl_table(): get a formatted gt table; you will need the gt package.

Examples

# return data hcl_dataframe("red")
#> name color hue chroma luminance #> 1 <NA> red 12.17395 179.0408 53.24059
hcl_dataframe("#FF0000")
#> name color hue chroma luminance #> 1 <NA> #FF0000 12.17395 179.0408 53.24059
hcl_dataframe(c("red", "green"))
#> name color hue chroma luminance #> 1 <NA> red 12.17395 179.0408 53.24059 #> 2 <NA> green 127.72353 135.7811 87.73510
# return formatted table hcl_table(c("red", "green"))
#> <style>html { #> font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif; #> } #> #> #mwlefoodfi .gt_table { #> display: table; #> border-collapse: collapse; #> margin-left: auto; #> margin-right: auto; #> color: #333333; #> font-size: 16px; #> font-weight: normal; #> font-style: normal; #> background-color: #FFFFFF; #> width: auto; #> border-top-style: solid; #> border-top-width: 2px; #> border-top-color: #A8A8A8; #> border-right-style: none; #> border-right-width: 2px; #> border-right-color: #D3D3D3; #> border-bottom-style: solid; #> border-bottom-width: 2px; #> border-bottom-color: #A8A8A8; #> border-left-style: none; #> border-left-width: 2px; #> border-left-color: #D3D3D3; #> } #> #> #mwlefoodfi .gt_heading { #> background-color: #FFFFFF; #> text-align: left; #> border-bottom-color: #FFFFFF; #> border-left-style: none; #> border-left-width: 1px; #> border-left-color: #D3D3D3; #> border-right-style: none; #> border-right-width: 1px; #> border-right-color: #D3D3D3; #> } #> #> #mwlefoodfi .gt_title { #> color: #333333; #> font-size: 125%; #> font-weight: initial; #> padding-top: 4px; #> padding-bottom: 4px; #> border-bottom-color: #FFFFFF; #> border-bottom-width: 0; #> } #> #> #mwlefoodfi .gt_subtitle { #> color: #333333; #> font-size: 85%; #> font-weight: initial; #> padding-top: 0; #> padding-bottom: 4px; #> border-top-color: #FFFFFF; #> border-top-width: 0; #> } #> #> #mwlefoodfi .gt_bottom_border { #> border-bottom-style: solid; #> border-bottom-width: 2px; #> border-bottom-color: #D3D3D3; #> } #> #> #mwlefoodfi .gt_col_headings { #> border-top-style: solid; #> border-top-width: 2px; #> border-top-color: #D3D3D3; #> border-bottom-style: solid; #> border-bottom-width: 2px; #> border-bottom-color: #D3D3D3; #> border-left-style: none; #> border-left-width: 1px; #> border-left-color: #D3D3D3; #> border-right-style: none; #> border-right-width: 1px; #> border-right-color: #D3D3D3; #> } #> #> #mwlefoodfi .gt_col_heading { #> color: #333333; #> background-color: #FFFFFF; #> font-size: 100%; #> font-weight: normal; #> text-transform: inherit; #> border-left-style: none; #> border-left-width: 1px; #> border-left-color: #D3D3D3; #> border-right-style: none; #> border-right-width: 1px; #> border-right-color: #D3D3D3; #> vertical-align: bottom; #> padding-top: 5px; #> padding-bottom: 6px; #> padding-left: 5px; #> padding-right: 5px; #> overflow-x: hidden; #> } #> #> #mwlefoodfi .gt_column_spanner_outer { #> color: #333333; #> background-color: #FFFFFF; #> font-size: 100%; #> font-weight: normal; #> text-transform: inherit; #> padding-top: 0; #> padding-bottom: 0; #> padding-left: 4px; #> padding-right: 4px; #> } #> #> #mwlefoodfi .gt_column_spanner_outer:first-child { #> padding-left: 0; #> } #> #> #mwlefoodfi .gt_column_spanner_outer:last-child { #> padding-right: 0; #> } #> #> #mwlefoodfi .gt_column_spanner { #> border-bottom-style: solid; #> border-bottom-width: 2px; #> border-bottom-color: #D3D3D3; #> vertical-align: bottom; #> padding-top: 5px; #> padding-bottom: 6px; #> overflow-x: hidden; #> display: inline-block; #> width: 100%; #> } #> #> #mwlefoodfi .gt_group_heading { #> padding: 8px; #> color: #333333; #> background-color: #FFFFFF; #> font-size: 100%; #> font-weight: initial; #> text-transform: inherit; #> border-top-style: solid; #> border-top-width: 2px; #> border-top-color: #D3D3D3; #> border-bottom-style: solid; #> border-bottom-width: 2px; #> border-bottom-color: #D3D3D3; #> border-left-style: none; #> border-left-width: 1px; #> border-left-color: #D3D3D3; #> border-right-style: none; #> border-right-width: 1px; #> border-right-color: #D3D3D3; #> vertical-align: middle; #> } #> #> #mwlefoodfi .gt_empty_group_heading { #> padding: 0.5px; #> color: #333333; #> background-color: #FFFFFF; #> font-size: 100%; #> font-weight: initial; #> border-top-style: solid; #> border-top-width: 2px; #> border-top-color: #D3D3D3; #> border-bottom-style: solid; #> border-bottom-width: 2px; #> border-bottom-color: #D3D3D3; #> vertical-align: middle; #> } #> #> #mwlefoodfi .gt_from_md > :first-child { #> margin-top: 0; #> } #> #> #mwlefoodfi .gt_from_md > :last-child { #> margin-bottom: 0; #> } #> #> #mwlefoodfi .gt_row { #> padding-top: 8px; #> padding-bottom: 8px; #> padding-left: 5px; #> padding-right: 5px; #> margin: 10px; #> border-top-style: solid; #> border-top-width: 1px; #> border-top-color: #D3D3D3; #> border-left-style: none; #> border-left-width: 1px; #> border-left-color: #D3D3D3; #> border-right-style: none; #> border-right-width: 1px; #> border-right-color: #D3D3D3; #> vertical-align: middle; #> overflow-x: hidden; #> } #> #> #mwlefoodfi .gt_stub { #> color: #333333; #> background-color: #FFFFFF; #> font-size: 100%; #> font-weight: initial; #> text-transform: inherit; #> border-right-style: solid; #> border-right-width: 2px; #> border-right-color: #D3D3D3; #> padding-left: 12px; #> } #> #> #mwlefoodfi .gt_summary_row { #> color: #333333; #> background-color: #FFFFFF; #> text-transform: inherit; #> padding-top: 8px; #> padding-bottom: 8px; #> padding-left: 5px; #> padding-right: 5px; #> } #> #> #mwlefoodfi .gt_first_summary_row { #> padding-top: 8px; #> padding-bottom: 8px; #> padding-left: 5px; #> padding-right: 5px; #> border-top-style: solid; #> border-top-width: 2px; #> border-top-color: #D3D3D3; #> } #> #> #mwlefoodfi .gt_grand_summary_row { #> color: #333333; #> background-color: #FFFFFF; #> text-transform: inherit; #> padding-top: 8px; #> padding-bottom: 8px; #> padding-left: 5px; #> padding-right: 5px; #> } #> #> #mwlefoodfi .gt_first_grand_summary_row { #> padding-top: 8px; #> padding-bottom: 8px; #> padding-left: 5px; #> padding-right: 5px; #> border-top-style: double; #> border-top-width: 6px; #> border-top-color: #D3D3D3; #> } #> #> #mwlefoodfi .gt_striped { #> background-color: rgba(128, 128, 128, 0.05); #> } #> #> #mwlefoodfi .gt_table_body { #> border-top-style: solid; #> border-top-width: 2px; #> border-top-color: #D3D3D3; #> border-bottom-style: solid; #> border-bottom-width: 2px; #> border-bottom-color: #D3D3D3; #> } #> #> #mwlefoodfi .gt_footnotes { #> color: #333333; #> background-color: #FFFFFF; #> border-bottom-style: none; #> border-bottom-width: 2px; #> border-bottom-color: #D3D3D3; #> border-left-style: none; #> border-left-width: 2px; #> border-left-color: #D3D3D3; #> border-right-style: none; #> border-right-width: 2px; #> border-right-color: #D3D3D3; #> } #> #> #mwlefoodfi .gt_footnote { #> margin: 0px; #> font-size: 90%; #> padding: 4px; #> } #> #> #mwlefoodfi .gt_sourcenotes { #> color: #333333; #> background-color: #FFFFFF; #> border-bottom-style: none; #> border-bottom-width: 2px; #> border-bottom-color: #D3D3D3; #> border-left-style: none; #> border-left-width: 2px; #> border-left-color: #D3D3D3; #> border-right-style: none; #> border-right-width: 2px; #> border-right-color: #D3D3D3; #> } #> #> #mwlefoodfi .gt_sourcenote { #> font-size: 90%; #> padding: 4px; #> } #> #> #mwlefoodfi .gt_left { #> text-align: left; #> } #> #> #mwlefoodfi .gt_center { #> text-align: center; #> } #> #> #mwlefoodfi .gt_right { #> text-align: right; #> font-variant-numeric: tabular-nums; #> } #> #> #mwlefoodfi .gt_font_normal { #> font-weight: normal; #> } #> #> #mwlefoodfi .gt_font_bold { #> font-weight: bold; #> } #> #> #mwlefoodfi .gt_font_italic { #> font-style: italic; #> } #> #> #mwlefoodfi .gt_super { #> font-size: 65%; #> } #> #> #mwlefoodfi .gt_footnote_marks { #> font-style: italic; #> font-size: 65%; #> } #> </style> #> <div id="mwlefoodfi" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;"><table class="gt_table"> #> #> <thead class="gt_col_headings"> #> <tr> #> <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">color</th> #> <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">hue</th> #> <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">chroma</th> #> <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">luminance</th> #> </tr> #> </thead> #> <tbody class="gt_table_body"> #> <tr> #> <td class="gt_row gt_right" style="background-color: #FF0000; color: #FFFFFF; font-family: &#39;Courier New&#39;; font-weight: bold; text-transform: lowercase;">red</td> #> <td class="gt_row gt_right">12.2</td> #> <td class="gt_row gt_right">179.0</td> #> <td class="gt_row gt_right">53.2</td> #> </tr> #> <tr> #> <td class="gt_row gt_right" style="background-color: #00FF00; color: #000000; font-family: &#39;Courier New&#39;; font-weight: bold; text-transform: lowercase;">green</td> #> <td class="gt_row gt_right">127.7</td> #> <td class="gt_row gt_right">135.8</td> #> <td class="gt_row gt_right">87.7</td> #> </tr> #> </tbody> #> #> #> </table></div>