| 1 | <h3>Authors</h3> |
| 2 | |
| 3 | <p>Jason C. Fisher, Reto Stauffer, Achim Zeileis |
| 4 | </p> |
| 5 | |
| 6 | |
| 7 | |
| 8 | <h2>Graphical User Interface for Choosing HCL Color Palettes</h2> |
| 9 | <h3>Description</h3> |
| 10 | |
| 11 | <p>A graphical user interface (GUI) for viewing, manipulating, and choosing HCL |
| 12 | color palettes. |
| 13 | </p> |
| 14 | |
| 15 | |
| 16 | |
| 17 | <h3>Details</h3> |
| 18 | |
| 19 | <p>Computes palettes based on the HCL (hue-chroma-luminance) color model (as |
| 20 | implemented by <code>polarLUV</code>). The GUIs interface the palette |
| 21 | functions <code>qualitative_hcl</code> for qualitative palettes, |
| 22 | <code>sequential_hcl</code> for sequential palettes with a single or |
| 23 | multiple hues, and <code>diverging_hcl</code> for diverging palettes (composed |
| 24 | from two single-hue sequential palettes). |
| 25 | </p> |
| 26 | <p>Two different GUIs are implemented and can be selected using the function |
| 27 | input argument <code>gui</code> (<code>"tcltk"</code> or <code>"shiny"</code>). Both GUIs |
| 28 | allows for interactive modification of the arguments of the respective |
| 29 | palette-generating functions, i.e., starting/ending hue (wavelength, type of |
| 30 | color), minimal/maximal chroma (colorfulness), minimal maximal luminance |
| 31 | (brightness, amount of gray), and a power transformations that control how |
| 32 | quickly/slowly chroma and/or luminance are changed through the palette. |
| 33 | Subsets of the parameters may not be applicable depending on the type of |
| 34 | palette chosen. See <code>qualitative_hcl</code> and Zeileis et al. (2009, 2019) for |
| 35 | a more detailed explanation of the different arguments. Stauffer et al. |
| 36 | (2015) provide more examples and guidance. |
| 37 | </p> |
| 38 | <p>Optionally, active palette can be illustrated by using a range of examples |
| 39 | such as a map, heatmap, scatter plot, perspective 3D surface etc. |
| 40 | </p> |
| 41 | <p>To demonstrate different types of deficiencies, the active palette may be |
| 42 | desaturated (emulating printing on a grayscale printer) and collapsed to |
| 43 | emulate different types of color-blindness (without red-green or green-blue |
| 44 | contrasts) using the <code>simulate_cvd</code> functions. |
| 45 | </p> |
| 46 | <p><code>choose_palette</code> by default starts the Tcl/Tk version of the GUI while |
| 47 | <code>hclwizard</code> by default starts the shiny version. <code>hcl_wizard</code> is |
| 48 | an alias for <code>hclwizard</code>. |
| 49 | </p> |
| 50 | |
| 51 | |
| 52 | |
| 53 | <h3>Value</h3> |
| 54 | |
| 55 | <p>Returns a palette-generating function with the selected arguments. |
| 56 | Thus, the returned function takes an integer argument and returns the |
| 57 | corresponding number of HCL colors by traversing HCL space through |
| 58 | interpolation of the specified hue/chroma/luminance/power values. |
| 59 | </p> |
| 60 | |
| 61 | |
| 62 | |
| 63 | <h2>HCL Color Palettes</h2> |
| 64 | <h3>Description</h3> |
| 65 | |
| 66 | <p>Qualitative, sequential (single-hue and multi-hue), and diverging |
| 67 | color palettes based on the HCL (hue-chroma-luminance) color model. |
| 68 | </p> |
| 69 | |
| 70 | |
| 71 | |
| 72 | <h3>Details</h3> |
| 73 | |
| 74 | <p>The HCL (hue-chroma-luminance) color model is a perceptual color model |
| 75 | obtained by using polar coordinates in CIE <code>LUV</code> space |
| 76 | (i.e., <code>polarLUV</code>), where steps of equal size correspond to |
| 77 | approximately equal perceptual changes in color. By taking polar coordinates |
| 78 | the resulting three dimensions capture the three perceptual axes very well: |
| 79 | hue is the type of color, chroma the colorfulness compared |
| 80 | to the corresponding gray, and luminance the brightness. This makes it relatively |
| 81 | easy to create balanced palettes through trajectories in this HCL space. |
| 82 | In contrast, in the more commonly-used <code>HSV</code> (hue-saturation-value) |
| 83 | model (a simple transformation of <code>RGB</code>), the three axes are |
| 84 | confounded so that luminance changes along with the hue leading to very |
| 85 | unbalanced palettes (see <code>rainbow_hcl</code> for further illustrations). |
| 86 | </p> |
| 87 | <p>Three types of palettes are derived based on the HCL model: </p> |
| 88 | |
| 89 | <ul> |
| 90 | <li><p> Qualitative: Designed for coding categorical information, i.e., |
| 91 | where no particular ordering of categories is available and every color |
| 92 | should receive the same perceptual weight. |
| 93 | </p> |
| 94 | </li> |
| 95 | <li><p> Sequential: Designed for coding ordered/numeric information, i.e., |
| 96 | where colors go from high to low (or vice versa). |
| 97 | </p> |
| 98 | </li> |
| 99 | <li><p> Diverging: Designed for coding numeric information around a central |
| 100 | neutral value, i.e., where colors diverge from neutral to two extremes. |
| 101 | </p> |
| 102 | </li></ul> |
| 103 | |
| 104 | <p>The corresponding functions are <code>qualitative_hcl</code>, <code>sequential_hcl</code>, |
| 105 | and <code>diverging_hcl</code>. Their construction principles are explained in more detail below. |
| 106 | At the core is the luminance axis (i.e., light-dark contrasts): |
| 107 | These are easily decoded by humans and matched to high-low differences in the underlying |
| 108 | data. Therefore, <code>sequential_hcl</code> palettes are always based on a <em>monotonic</em> |
| 109 | luminance sequence whereas the colors in a <code>qualitative_hcl</code> palette all have the |
| 110 | <em>same</em> luminance. Finally, <code>diverging_hcl</code> palettes use the same monotonic |
| 111 | luminance sequence in both “arms” of the palette, i.e., correspond to |
| 112 | two balanced sequential palettes diverging from the same neutral value. |
| 113 | The other two axes, hue and chroma, are used to enhance the luminance information and/or |
| 114 | to further discriminate the color. |
| 115 | </p> |
| 116 | <p>All three palette functions specify trajectories in HCL space and hence need either |
| 117 | single values or intervals of the coordinates <code>h</code>, <code>c</code>, <code>l</code>. Their |
| 118 | interfaces are always designed such that <code>h</code>, <code>c</code>, <code>l</code> can take vector |
| 119 | arguments (as needed) but alternatively or additionally <code>h1</code>/<code>h2</code>, |
| 120 | <code>c1</code>/<code>cmax</code>/<code>c2</code>, and <code>l1</code>/<code>l2</code> can be specified. If so, |
| 121 | the latter coordinates overwrite the former. |
| 122 | </p> |
| 123 | <p><code>qualitative_hcl</code> distinguishes the underlying categories by a sequence of |
| 124 | hues while keeping both chroma and luminance constant to give each color in the |
| 125 | resulting palette the same perceptual weight. Thus, <code>h</code> should be a pair of |
| 126 | hues (or equivalently <code>h1</code> and <code>h2</code> can be used) with the starting and |
| 127 | ending hue of the palette. Then, an equidistant sequence between these hues is |
| 128 | employed, by default spanning the full color wheel (i.e, the full 360 degrees). |
| 129 | Chroma <code>c</code> (or equivalently <code>c1</code>) and luminance <code>l</code> (or equivalently |
| 130 | <code>l1</code>) are constants. |
| 131 | </p> |
| 132 | <p><code>sequential_hcl</code> codes the underlying numeric values by a monotonic sequence |
| 133 | of increasing (or decreasing) luminance. Thus, the <code>l</code> argument should provide |
| 134 | a vector of length 2 with starting and ending luminance (equivalently, <code>l1</code> and |
| 135 | <code>l2</code> can be used). Without chroma (i.e., <code>c = 0</code>), this simply corresponds |
| 136 | to a grayscale palette like <code>gray.colors</code>. For adding chroma, a simple |
| 137 | strategy would be to pick a single hue (via <code>h</code> or <code>h1</code>) and then decrease |
| 138 | chroma from some value (<code>c</code> or <code>c1</code>) to zero (i.e., gray) along with |
| 139 | increasing luminance. For bringing out the extremes (a dark high-chroma color vs. |
| 140 | a light gray) this is already very effective. For distinguishing also colors in the |
| 141 | middle two strategies can be employed: (a) Hue can be varied as well by specifying an |
| 142 | interval of hues in <code>h</code> (or beginning hue <code>h1</code> and ending hue <code>h2</code>). |
| 143 | (b) Instead of a decreasing chroma a triangular chroma trajectory can be employed |
| 144 | from <code>c1</code> over <code>cmax</code> to <code>c2</code> (or equivalently a vector <code>c</code> of |
| 145 | length 3). This yields high-chroma colors in the middle of the palette that are |
| 146 | more easily distinguished from the dark and light extremes. Finally, instead of |
| 147 | employing linear trajectories, power transformations are supported in chroma and |
| 148 | luminance via a vector <code>power</code> (or separate <code>p1</code> and <code>p2</code>). If |
| 149 | <code>power[2]</code> (or <code>p2</code>) for the luminance trajectory is missing, it defaults |
| 150 | to <code>power[1]</code>/<code>p1</code> from the chroma trajectory. |
| 151 | </p> |
| 152 | <p><code>diverging_hcl</code> codes the underlying numeric values by a triangular luminance |
| 153 | sequence with different hues in the left and in the right arm of the palette. Thus, |
| 154 | it can be seen as a combination of two sequential palettes with some restrictions: |
| 155 | (a) a single hue is used for each arm of the palette, (b) chroma and luminance trajectory |
| 156 | are balanced between the two arms, (c) the neutral central value has zero chroma. |
| 157 | To specify such a palette a vector of two hues <code>h</code> (or equivalently <code>h1</code> |
| 158 | and <code>h2</code>), either a single chroma value <code>c</code> (or <code>c1</code>) or a vector |
| 159 | of two chroma values <code>c</code> (or <code>c1</code> and <code>cmax</code>), a vector of two |
| 160 | luminances <code>l</code> (or <code>l1</code> and <code>l2</code>), and power parameter(s) <code>power</code> |
| 161 | (or <code>p1</code> and <code>p2</code>) are used. For more flexible diverging palettes without |
| 162 | the restrictrictions above (and consequently more parameters) |
| 163 | <code>divergingx_hcl</code> is available. For backward compatibility, <code>diverge_hcl</code> |
| 164 | is a copy of <code>diverging_hcl</code>. |
| 165 | </p> |
| 166 | <p>To facilitate using HCL-based palettes a wide range of example palettes are |
| 167 | provided in the package and can be specified by a name instead of a set of |
| 168 | parameters/coordinates. The examples have been taken from the literature and many |
| 169 | approximate color palettes from other software packages such as ColorBrewer.org |
| 170 | (<span class="pkg">RColorBrewer</span>), CARTO colors (<span class="pkg">rcartocolor</span>), <span class="pkg">scico</span>, or <span class="pkg">virids</span>. The |
| 171 | function <code>hcl_palettes</code> can be used to query the available pre-specified palettes. It |
| 172 | comes with a <code>print</code> method (listing names and types), a <code>summary</code> method |
| 173 | (additionally listing the underlying parameters/coordinates), and a <code>plot</code> |
| 174 | method that creates a <code>swatchplot</code> with suitable labels. |
| 175 | </p> |
| 176 | |
| 177 | |
| 178 | |
| 179 | <h3>Value</h3> |
| 180 | |
| 181 | <p><code>qualitative_hcl</code>, <code>sequential_hcl</code>, <code>diverging_hcl</code> return |
| 182 | a vector of <code>n</code> color strings (hex codes). |
| 183 | </p> |
| 184 | <p>The function <code>hcl_palettes</code> returns a data frame of class <code>"hcl_palettes"</code> |
| 185 | where each row contains information about one of the requested palettes (name, type, |
| 186 | HCL trajectory coordinates). Suitable <code>print</code>, <code>summary</code>, and <code>plot</code> |
| 187 | methods are available. |
| 188 | </p> |
| 189 | |
| 190 | |
| 191 | |
| 192 | <h2>Color Spectrum Plot</h2> |
| 193 | <h3>Description</h3> |
| 194 | |
| 195 | <p>Visualization of color palettes (given as hex codes) in HCL and/or RGB |
| 196 | coordinates. |
| 197 | </p> |
| 198 | |
| 199 | |
| 200 | |
| 201 | <h3>Details</h3> |
| 202 | |
| 203 | <p>The function <code>specplot</code> transforms a given color palette in hex codes |
| 204 | into their HCL (<code>polarLUV</code>) and/or RGB |
| 205 | (<code>sRGB</code>) coordinates. As the hues for low-chroma |
| 206 | colors are not (or poorly) identified, by default a smoothing is applied to |
| 207 | the hues (<code>fix = TRUE</code>). Also, to avoid jumps from 0 to 360 or vice |
| 208 | versa, the hue coordinates are shifted suitably. |
| 209 | </p> |
| 210 | <p>By default (<code>plot = TRUE</code>), the resulting HCL and optionally RGB coordinates are |
| 211 | visualized by simple line plots along with the color palette <code>x</code> |
| 212 | itself. The x-axis simply gives the ordering of the colors in the palette |
| 213 | The y-axis depicts the following information: (1) Hue is drawn in red and |
| 214 | coordinates are indicated on the axis on the right with range [0, 360] or |
| 215 | (if necessary) [-360, 360]. (2) Chroma is drawn in green with coordinates on |
| 216 | the left axis. The range [0, 100] is used unless the palette necessitates |
| 217 | higher chroma values. (3) Luminance is drawn in blue with coordinates on the |
| 218 | left axis in the range [0, 100]. Luminance (and hence also chroma) is on |
| 219 | the left axis because it is arguably most important for understanding the |
| 220 | type of palette (qualitative vs. sequential vs. diverging). To facilitate |
| 221 | reading the legend the reversed order Luminance / Chroma / Hue is used so that |
| 222 | the legend labels are closer to the axis they pertain to. |
| 223 | </p> |
| 224 | <p>For comparing two palettes, <code>specplot(x, y)</code> can be used which adds |
| 225 | lines (dashed, by default) corresponding to the <code>y</code> palette HCL/RGB |
| 226 | coordinates in the display. |
| 227 | </p> |
| 228 | |
| 229 | |
| 230 | |
| 231 | <h3>Value</h3> |
| 232 | |
| 233 | <p><code>specplot</code> invisibly returns a list with components |
| 234 | </p> |
| 235 | <table> |
| 236 | <tr><td><code>HCL</code></td> |
| 237 | <td> |
| 238 | <p>a matrix of HCL coordinates,</p> |
| 239 | </td></tr> |
| 240 | <tr><td><code>RGB</code></td> |
| 241 | <td> |
| 242 | <p>a matrix of sRGB coordinates,</p> |
| 243 | </td></tr> |
| 244 | <tr><td><code>hex</code></td> |
| 245 | <td> |
| 246 | <p>original color palette <code>x</code>.</p> |
| 247 | </td></tr> |
| 248 | </table> |
| 249 | |
| 250 | |
| 251 | |
| 252 | <h2>Palette Plot in HCL Space</h2> |
| 253 | <h3>Description</h3> |
| 254 | |
| 255 | <p>Visualization of color palettes in HCL space projections. |
| 256 | </p> |
| 257 | |
| 258 | |
| 259 | |
| 260 | <h3>Details</h3> |
| 261 | |
| 262 | <p>The function <code>hclplot</code> is an auxiliary function for illustrating |
| 263 | the trajectories of color palettes in two-dimensional HCL space projections. |
| 264 | It collapses over one of the three coordinates (either the hue H or the |
| 265 | luminance L) and displays a heatmap of colors combining the remaining |
| 266 | two dimensions. The coordinates for the given color palette are highlighted |
| 267 | to bring out its trajectory. |
| 268 | </p> |
| 269 | <p>The function <code>hclplot</code> has been designed to work well with the |
| 270 | <code>hcl_palettes</code> in this package. While it is possible to apply |
| 271 | it to other color palettes as well, the results might look weird or confusing |
| 272 | if these palettes are constructed very differently (e.g., as in the highly |
| 273 | saturated base R palettes). |
| 274 | </p> |
| 275 | <p>More specifically, the following palettes can be visualized well: </p> |
| 276 | |
| 277 | <ul> |
| 278 | <li><p> Qualitative with (approximately) constant luminance. In this case, |
| 279 | <code>hclplot</code> shows a hue-chroma plane (in polar coordinates), keeping |
| 280 | luminance at a fixed level (by default displayed in the main title of |
| 281 | the plot). If the luminance is, in fact, not approximately constant, |
| 282 | the luminance varies along with hue and chroma, using a simple linear |
| 283 | function (fitted by least squares). |
| 284 | <code>hclplot</code> shows a chroma-luminance plane, keeping hue at a fixed |
| 285 | level (by default displayed in the main title of the plot). If the hue |
| 286 | is, in fact, not approximately constant, the hue varies along with |
| 287 | chroma and luminance, using a simple linear function (fitted by least |
| 288 | squares. |
| 289 | </p> |
| 290 | </li> |
| 291 | <li><p> Diverging with two (approximately) constant hues: This case is |
| 292 | visualized with two back-to-back sequential displays. |
| 293 | </p> |
| 294 | </li></ul> |
| 295 | |
| 296 | <p>To infer the type of display to use, by default, the following heuristic is |
| 297 | used: If luminance is not approximately constant (range > 10) and follows |
| 298 | rougly a triangular pattern, a diverging display is used. If luminance is |
| 299 | not constant and follows roughly a linear pattern, a sequential display is |
| 300 | used. Otherwise a qualitative display is used. |
| 301 | </p> |
| 302 | |
| 303 | |
| 304 | |
| 305 | <h3>Value</h3> |
| 306 | |
| 307 | <p><code>hclplot</code> invisibly returns a matrix with the HCL coordinates corresponding to <code>x</code>. |
| 308 | </p> |
| 309 | |
| 310 | |
| 311 | |
| 312 | <h3>References</h3> |
| 313 | |
| 314 | <p>Zeileis A, Hornik K, Murrell P (2009). Escaping RGBland: |
| 315 | Selecting Colors for Statistical Graphics. <em>Computational Statistics & |
| 316 | Data Analysis</em>, <b>53</b>, 3259–3270. |
| 317 | doi:10.1016/j.csda.2008.11.033 |
| 318 | Preprint available from |
| 319 | https://www.zeileis.org/papers/Zeileis+Hornik+Murrell-2009.pdf. |
| 320 | </p> |
| 321 | <p>Stauffer R, Mayr GJ, Dabernig M, Zeileis A (2015). Somewhere over the |
| 322 | Rainbow: How to Make Effective Use of Colors in Meteorological |
| 323 | Visualizations. <em>Bulletin of the American Meteorological Society</em>, |
| 324 | <b>96</b>(2), 203–216. |
| 325 | doi:10.1175/BAMS-D-13-00155.1 |
| 326 | </p> |
| 327 | <p>Zeileis A, Fisher JC, Hornik K, Ihaka R, McWhite CD, Murrell P, Stauffer R, Wilke CO (2020). |
| 328 | “colorspace: A Toolbox for Manipulating and Assessing Colors and Palettes.” |
| 329 | <em>Journal of Statistical Software</em>, <b>96</b>(1), 1–49. doi:10.18637/jss.v096.i01 |
| 330 | </p> |
| 331 | |
| 332 | |
| 333 |