Title: | Distinct Colour Palettes Based on 'iwanthue' |
---|---|
Description: | Creating effective colour palettes for figures is challenging. This package generates and plot palettes of optimally distinct colours in perceptually uniform colour space, based on 'iwanthue' <http://tools.medialab.sciences-po.fr/iwanthue/>. This is done through k-means clustering of CIE Lab colour space, according to user-selected constraints on hue, chroma, and lightness. |
Authors: | John Baumgartner [aut, cre] , Russell Dinnage [aut] |
Maintainer: | John Baumgartner <[email protected]> |
License: | LGPL (>= 3) |
Version: | 0.2.0.9000 |
Built: | 2024-10-14 03:00:50 UTC |
Source: | https://github.com/johnbaums/hues |
This package generates and plot palettes of optimally distinct colours in perceptually uniform colour space, based on iwanthue. This is done through k-means clustering of CIE Lab colour space, according to user-selected constraints on hue, chroma, and lightness.
These functions allow you to use iwanthue()
generated palettes with
ggplot2
plots. You need ggplot2
installed for these to work. Note these
only work with discrete scales.
scale_colour_iwanthue( ..., hmin = 0, hmax = 360, cmin = 0, cmax = 180, lmin = 0, lmax = 100, random = FALSE, aesthetics = "colour" ) scale_color_iwanthue( ..., hmin = 0, hmax = 360, cmin = 0, cmax = 180, lmin = 0, lmax = 100, random = FALSE, aesthetics = "colour" ) scale_fill_iwanthue( ..., hmin = 0, hmax = 360, cmin = 0, cmax = 180, lmin = 0, lmax = 100, random = FALSE, aesthetics = "fill" )
scale_colour_iwanthue( ..., hmin = 0, hmax = 360, cmin = 0, cmax = 180, lmin = 0, lmax = 100, random = FALSE, aesthetics = "colour" ) scale_color_iwanthue( ..., hmin = 0, hmax = 360, cmin = 0, cmax = 180, lmin = 0, lmax = 100, random = FALSE, aesthetics = "colour" ) scale_fill_iwanthue( ..., hmin = 0, hmax = 360, cmin = 0, cmax = 180, lmin = 0, lmax = 100, random = FALSE, aesthetics = "fill" )
... |
Arguments to pass on to |
hmin |
Numeric, in the range |
hmax |
Numeric, in the range |
cmin |
Numeric, in the range |
cmax |
Numeric, in the range |
lmin |
Numeric, in the range |
lmax |
Numeric, in the range |
random |
Logical. If |
aesthetics |
Character string or vector of character strings listing the
name(s) of the aesthetic(s) that this scale works with. This can be useful,
for example, to apply colour settings to the colour and fill aesthetics at
the same time, via |
A ScaleDiscrete
object that can be added to a ggplot
object.
Russell Dinnage [email protected]
if (require('ggplot2')) { ggplot(iris, aes(x=Petal.Width, y=Petal.Length)) + geom_point(aes(color=Species), size=10) + scale_colour_iwanthue() ggplot(iris, aes(x=Petal.Width, y=Petal.Length)) + geom_point(aes(color=Species), size=10) + scale_colour_iwanthue(hmax = 90) }
if (require('ggplot2')) { ggplot(iris, aes(x=Petal.Width, y=Petal.Length)) + geom_point(aes(color=Species), size=10) + scale_colour_iwanthue() ggplot(iris, aes(x=Petal.Width, y=Petal.Length)) + geom_point(aes(color=Species), size=10) + scale_colour_iwanthue(hmax = 90) }
Generate a palette of distinct colours through k-means clustering of CIE Lab colour space.
iwanthue( n, hmin = 0, hmax = 360, cmin = 0, cmax = 180, lmin = 0, lmax = 100, plot = FALSE, random = FALSE )
iwanthue( n, hmin = 0, hmax = 360, cmin = 0, cmax = 180, lmin = 0, lmax = 100, plot = FALSE, random = FALSE )
n |
Numeric. The number of colours to generate. |
hmin |
Numeric, in the range |
hmax |
Numeric, in the range |
cmin |
Numeric, in the range |
cmax |
Numeric, in the range |
lmin |
Numeric, in the range |
lmax |
Numeric, in the range |
plot |
Logical. Should the colour swatches be plotted (using
|
random |
Logical. If |
Note that iwanthue
currently doesn't support hmin
greater than
hmax
(which should be allowed, since hue is circular).
A vector of n
colours (as hexadecimal strings), representing
centers of clusters determined through k-means clustering of the CIE Lab
colour space delimited by hmin
, hmax
, cmin
, cmax
, lmin
and
lmax
.
Examples follow those presented at iwanthue - colors for data scientists
iwanthue(5) iwanthue(5, plot=TRUE) iwanthue(5, 0, 240, 0, 24, 0, 100, plot=TRUE) # shades iwanthue(5, 0, 360, 0, 54, 67, 100, plot=TRUE) # pastel iwanthue(5, 0, 360, 54, 180, 27, 67, plot=TRUE) # pimp iwanthue(5, 0, 360, 36, 180, 13, 73, plot=TRUE) # intense iwanthue(3, 0, 300, 60, 180, 73, 100, plot=TRUE) # fluoro iwanthue(3, 220, 260, 12, 150, 0, 53, plot=TRUE) # blue ocean
iwanthue(5) iwanthue(5, plot=TRUE) iwanthue(5, 0, 240, 0, 24, 0, 100, plot=TRUE) # shades iwanthue(5, 0, 360, 0, 54, 67, 100, plot=TRUE) # pastel iwanthue(5, 0, 360, 54, 180, 27, 67, plot=TRUE) # pimp iwanthue(5, 0, 360, 36, 180, 13, 73, plot=TRUE) # intense iwanthue(3, 0, 300, 60, 180, 73, 100, plot=TRUE) # fluoro iwanthue(3, 220, 260, 12, 150, 0, 53, plot=TRUE) # blue ocean
Plot named colour swatches for a vector of colours.
swatch(x)
swatch(x)
x |
a vector of colours, specified as: colour names (i.e. colour names
returned by |
NULL
. The colour swatch is plotted to the active plotting device.
swatch(colours()[1:10]) swatch(1:4) swatch(iwanthue(5))
swatch(colours()[1:10]) swatch(1:4) swatch(iwanthue(5))