GetTolColors | R Documentation |
This function creates a vector of n
colors from
qualitative, diverging, and sequential color schemes by Paul Tol (2018).
GetTolColors(
n,
scheme = "smooth rainbow",
alpha = NULL,
start = 0,
end = 1,
bias = 1,
reverse = FALSE,
blind = NULL,
gray = FALSE
)
n |
'integer'. Number of colors to be in the palette. The maximum number of colors in a generated palette is dependent on the specified color scheme, see ‘Details’ section for maximum values. |
scheme |
'character'.
Color scheme name: specify
|
alpha |
'numeric'.
Alpha transparency, values range from 0 (fully transparent) to 1 (fully opaque).
Specify as |
start , end |
'numeric'.
Starting and ending color level in the palette, respectively.
Specified as a number in the interval from 0 to 1.
Applies only to interpolated color schemes:
|
bias |
'numeric'.
Interpolation bias where larger values result in more widely spaced colors at the high end.
See |
reverse |
'logical'. Whether to reverse the color order in the palette. |
blind |
'character'.
Type of color blindness to simulate: specify |
gray |
'logical'.
Whether to subset the |
The maximum number of colors in a palette is:
n = 6
for "pale"
and "dark"
;
n = 8
for "bright"
and "vibrant"
;
n = 10
for "muted"
, "light"
, "YlOrBr"
, "BuRd"
, and "PRGn"
;
n = 14
for "ground cover"
; and
n = 24
for "discrete rainbow"
.
For "sunset"
, "BuRd"
, "PRGn"
, "YlOrBr"
, and "smooth rainbow"
,
a continuous version of the scheme is available that
has no limit placed on the number of colors in a palette.
The exception to these limits occurs when the gray
argument is true: in that case
n = 3
for "bright"
, n = 4
for "vibrant"
, and n = 5
for "muted"
.
Color schemes "pale"
, "dark"
, and "ground cover"
are
intended to be accessed in their entirety and subset using vector element names.
The very specific "ground cover"
scheme is a color-blind safe version of the
AVHRR
global land cover classification (Hansen and others, 1998).
Returns an object of class 'Tol' that inherits behavior from the 'character' class.
The object is comprised of a 'character' vector of n
colors in the RGB color system.
Colors are specified with a string of the form "#RRGGBB"
or "#RRGGBBAA"
where RR
, GG
, BB
, and AA
are the
red, green, blue, and alpha hexadecimal values (00 to FF), respectively.
Attributes of the returned object include:
"names"
, the informal names assigned to colors in the palette,
where NULL
indicates no color names are specified;
"bad"
, a 'character' string giving the color meant for bad data, in hexadecimal format,
where NA
indicates no bad color is specified; and
"call"
, an object of class 'call' giving the unevaluated function call (expression)
that can be used to reproduce the color palette.
Use the eval
function to evaluate the "call"
argument.
A simple plot
method is provided for the 'Tol' class that
shows a palette of colors using a sequence of shaded rectangles,
see ‘Examples’ section for usage.
The sequential color scheme "YlOrBr"
works well for conversion to gray scale.
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
Hansen, M., DeFries, R., Townshend, J.R.G., and Sohlberg, R., 1998, UMD Global Land Cover Classification, 1 Kilometer, 1.0: Department of Geography, University of Maryland, College Park, Maryland, 1981-1994.
Tol, Paul, 2018, Colour Schemes: SRON Technical Note, doc. no. SRON/EPS/TN/09-002, issue 3.0, 17 p., accessed August 29, 2018 at https://personal.sron.nl/~pault/data/colourschemes.pdf.
col2rgb
cols <- GetTolColors(n = 10)
print(cols)
plot(cols)
# Qualitative color schemes (scheme)
op <- par(mfrow = c(6, 1), oma = c(0, 0, 0, 0))
plot(GetTolColors(7, scheme = "bright"))
plot(GetTolColors(7, scheme = "vibrant"))
plot(GetTolColors(9, scheme = "muted"))
plot(GetTolColors(6, scheme = "pale"))
plot(GetTolColors(6, scheme = "dark"))
plot(GetTolColors(9, scheme = "light"))
par(op)
op <- par(oma = c(1, 0, 0, 0), cex = 0.7)
plot(GetTolColors(14, scheme = "ground cover"))
par(op)
# Diverging color schemes (scheme)
op <- par(mfrow = c(6, 1), oma = c(0, 0, 0, 0))
plot(GetTolColors( 11, scheme = "sunset"))
plot(GetTolColors(255, scheme = "sunset"))
plot(GetTolColors( 9, scheme = "BuRd"))
plot(GetTolColors(255, scheme = "BuRd"))
plot(GetTolColors( 9, scheme = "PRGn"))
plot(GetTolColors(255, scheme = "PRGn"))
par(op)
# Sequential color schemes (scheme)
op <- par(mfrow = c(5, 1), oma = c(0, 0, 0, 0))
plot(GetTolColors( 9, scheme = "YlOrBr"))
plot(GetTolColors(255, scheme = "YlOrBr"))
plot(GetTolColors( 23, scheme = "discrete rainbow"))
plot(GetTolColors( 34, scheme = "smooth rainbow"))
plot(GetTolColors(255, scheme = "smooth rainbow"))
par(op)
# Alpha transparency (alpha)
op <- par(mfrow = c(5, 1), oma = c(0, 0, 0, 0))
plot(GetTolColors(34, alpha = 1.0))
plot(GetTolColors(34, alpha = 0.8))
plot(GetTolColors(34, alpha = 0.6))
plot(GetTolColors(34, alpha = 0.4))
plot(GetTolColors(34, alpha = 0.2))
par(op)
# Color levels (start, end)
op <- par(mfrow = c(4, 1), oma = c(0, 0, 0, 0))
plot(GetTolColors(255, start = 0.0, end = 1.0))
plot(GetTolColors(255, start = 0.0, end = 0.5))
plot(GetTolColors(255, start = 0.5, end = 1.0))
plot(GetTolColors(255, start = 0.3, end = 0.9))
par(op)
# Interpolation bias (bias)
op <- par(mfrow = c(7, 1), oma = c(0, 0, 0, 0))
plot(GetTolColors(255, bias = 0.4))
plot(GetTolColors(255, bias = 0.6))
plot(GetTolColors(255, bias = 0.8))
plot(GetTolColors(255, bias = 1.0))
plot(GetTolColors(255, bias = 1.2))
plot(GetTolColors(255, bias = 1.4))
plot(GetTolColors(255, bias = 1.6))
par(op)
# Reverse colors (reverse)
op <- par(mfrow = c(2, 1), oma = c(0, 0, 0, 0), cex = 0.7)
plot(GetTolColors(10, reverse = FALSE))
plot(GetTolColors(10, reverse = TRUE))
par(op)
# Color blindness (blind)
op <- par(mfrow = c(5, 1), oma = c(0, 0, 0, 0))
plot(GetTolColors(34, blind = NULL))
plot(GetTolColors(34, blind = "deutan"))
plot(GetTolColors(34, blind = "protan"))
plot(GetTolColors(34, blind = "tritan"))
plot(GetTolColors(34, blind = "monochromacy"))
par(op)
# Gray-scale preparation (gray)
op <- par(mfrow = c(6, 1), oma = c(0, 0, 0, 0))
plot(GetTolColors(3, "bright", gray = TRUE))
plot(GetTolColors(3, "bright", gray = TRUE, blind = "m"))
plot(GetTolColors(4, "vibrant", gray = TRUE))
plot(GetTolColors(4, "vibrant", gray = TRUE, blind = "m"))
plot(GetTolColors(5, "muted", gray = TRUE))
plot(GetTolColors(5, "muted", gray = TRUE, blind = "m"))
par(op)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.