ColorPal: ColorBrewer colour palettes

View source: R/ColorPal.R

ColorPalR Documentation

ColorBrewer colour palettes

Description

Obtain a colour palette from the ColorBrewer 2.0 collection for use in standard plots, image plots, or filled contour plots.

Usage

ColorPal(name = "RdYlBu", n.in = NULL, n.out = NULL, rev = FALSE, fun = FALSE)

Arguments

name

a palette name from the ColorBrewer 2.0 collection; defaults to the diverging RdYlBu palette.

n.in

integer number of different input colours in the palette, minimum is 3, the possible maximum number of colours depends on the chosen palette. Default NULL means to use this maximum number of colours.

n.out

integer number of colours for the output vector if fun = FALSE; the default is to output as many colours as used for the palette, so n.out is set to the value of n.in. If a different number is specified here, the corresponding colours are obtained from interpolation between the range of colours spanned by the palette for the given number n.in; see the examples.

rev

logical; set to TRUE to reverse the order of colours in the palette.

fun

logical to control the return type; if set to FALSE (the default) returned is simply a character vector of length n.out with the hexadecimal colour codes from the requested palette. Set to TRUE to instead obtain a function that takes an integer argument (the required number of colours) and returns a character vector of hexadecimal colour codes, which is needed, e.g., for a filled contour plot (filled.contour).

Value

either a character vector of hexadecimal colour codes, or a function to return a colour code vector.

Author(s)

Thomas Münch

Source

The ColorBrewer 2.0 collection can be viewed interactively at https://colorbrewer2.org.

See Also

colorRampPalette; brewer.pal

Examples


# default palette
ColorPal()

# reverse the order of colours
ColorPal(rev = TRUE)

# return instead a colour palette function for use in filled contour plots
fun <- ColorPal(fun = TRUE)
fun(5)

# note that the following two colour vectors are not identical:
ColorPal(n.in = 11, n.out = 3)
ColorPal(n.in = 3)
# while the first call gives three colours from interpolating between the
# full range of colours for the given palette (so that in this example the
# first and last returned colour correspond to the outermost colours in the
# given palette and the second colour is some midpoint value), the second
# result is a subset of three colours from the specified palette, which do
# not necessarily span the possible palette range and which are determined by
# the 'RColorBrewer::brewer.pal()' function. In this context, also compare
# the above results to the following call:
ColorPal(n.in = 3, n.out = 11)


EarthSystemDiagnostics/grfxtools documentation built on Aug. 5, 2023, 1:43 p.m.