squash (version 1.0.8)

makecmap: Generate a color map from numeric values to colors

Description

Generate a color map from numeric values to a contiguous set of colors.

Usage

makecmap(x, n = 10, breaks = pretty, 
  symm = FALSE, base = NA, 
  colFn = jet, col.na = NA, 
  right = FALSE, include.lowest = FALSE, ...)

Arguments

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 x[i] equal to the lowest (or highest, for right = FALSE) breaks value should be included.

Further arguments to breaks.

Value

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)

Details

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.

See Also

cmap and colorgram use the mappings generated by this function.

hkey plots a color key.

Consider setting breaks = prettyInt or breaks = prettyLog

Examples

Run this code
# NOT RUN {
  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))


# }

Run the code above in your browser using DataLab