Description Usage Arguments Details Value See Also Examples
Generate a color map from numeric values to a contiguous set of colors.
1 2 3 4 |
x |
A vector of numbers (only the finite range is used). |
n |
Approximate number of color levels desired. |
breaks |
A function to generate breakpoints, or the breakpoints themselves. |
symm |
Extend the mapping domain to be symmetric around zero? |
base |
Base for log scale, or NA to use a linear scale. |
colFn |
A function that generates contiguous colors. |
col.na |
Color to use for missing values. |
right |
Logical; if TRUE, the intervals will be closed on the right (and open on the left). |
include.lowest |
Logical, indicating if an |
... |
Further arguments to |
The general point of this function is to automatically generate a mapping that can be used in combination with cmap
to represent numeric data with colors in a consistent way.
colFn
should be a function that returns a vector of colors of specified length, such as rainbow
, greyscale
. Custom functions of this type can be generated with colorRampPalette
.
The breakpoints can be specified explicitly by setting breaks
to a vector of numbers, in which case x
is ignored. Otherwise, the breakpoints are chosen to be nice, relatively round values (using pretty
, or another function passed to breaks
) covering the finite range of x
.
If symm
is TRUE, the map domain is extended such that it is symmetric around zero. This can be useful when using divergent color palettes to ensure that the zero point is a neutral color.
If base
is specified, the breakpoints are generated using log-transformed data. However, setting breaks = prettyLog
might be preferable.
A list with the following components:
breaks |
Breakpoints (numeric vector). |
colors |
Colors (character or numeric vector). |
base |
(as supplied in arguments) |
col.na |
(as supplied in arguments) |
right |
(as supplied in arguments) |
include.lowest |
(as supplied in arguments) |
cmap
and colorgram
use the mappings generated by this function.
hkey
plots a color key.
Consider setting breaks = prettyInt
or breaks = prettyLog
1 2 3 4 5 6 7 8 9 10 11 | attach(iris)
map1 <- makecmap(Petal.Length)
myColors <- cmap(Petal.Length, map = map1)
plot(Sepal.Length, Sepal.Width, col = myColors, pch = 16)
hkey(map1, title = 'Petal.Length')
## Compare the 'breaks' element in the following:
x <- rnorm(100) * 1000
str(makecmap(x))
str(makecmap(x, breaks = c(-Inf, -1000, 0, 1000, Inf)))
str(makecmap(x, breaks = prettyLog))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.