R: Apply a color map to numeric data

cmap {squash} | R Documentation

## Apply a color map to numeric data

### Description

Map numeric (scalars, vectors, matrices) into colors, (optionally) using a specified color map.

### Usage

    cmap(x, map, outlier = NULL, ...)

### Arguments

`x` | Something numeric (vector, matrix).
`map` | The color map to use (as created by `makecmap`). If missing, a color map is created.
`outlier` | Color for values outside the map domain, or NULL to generate an error in case of such values (see Details).
`...` | Arguments passed to `makecmap`, if `map` is undefined.

### Details

Values in `x` outside the domain of `map` cause either an error (if `outlier=NULL`) or a warning (otherwise).

### Value

Something of the same size as `x`. May be character (RGB) or integer (palettes) depending on the color map used. Dimensions and dimnames are preserved.

### See Also

`makecmap`. Also, `as.raster` and `level.colors` have similar functionality.

### Examples

      x <- y <- 1:50
      mat1 <- outer(x, y)

      ## several ways of visualizing the matrix mat1:
      plot(col(mat1), row(mat1), col = cmap(mat1), pch = 16)

      cimage(x, y, zcol = cmap(mat1))

      colorgram(x = x, y = y, z = mat1)

      ## treatment of out-of-domain values
      map <- makecmap(0:100, colFn = greyscale)
      x <- y <- -10:10
      mat2 <- outer(x, y, "*")

      ## Not run:
      ## Values outside the domain of "map" generate an error...
      plot(col(mat2), row(mat2), col = cmap(mat2, map), pch = 15, cex = 2)

      ## ... unless we specify "outlier", but this still generates a warning
      plot(col(mat2), row(mat2), col = cmap(mat2, map, outlier = 'red'), pch = 15, cex = 2)

    ## End(Not run)

[Package squash version 1.0.8 Index]