ColorPal | R Documentation |
Obtain a colour palette from the ColorBrewer 2.0 collection for use in standard plots, image plots, or filled contour plots.
ColorPal(name = "RdYlBu", n.in = NULL, n.out = NULL, rev = FALSE, fun = FALSE)
name |
a palette name from the ColorBrewer 2.0 collection; defaults to
the diverging |
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 |
n.out |
integer number of colours for the output vector if |
rev |
logical; set to |
fun |
logical to control the return type; if set to |
either a character vector of hexadecimal colour codes, or a function to return a colour code vector.
Thomas Münch
The ColorBrewer 2.0 collection can be viewed interactively at https://colorbrewer2.org.
colorRampPalette
;
brewer.pal
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.