R: Replace a vector of numbers by a gradient of colors

smoothPalette {tagcloud} | R Documentation

## Replace a vector of numbers by a gradient of colors

### Description

Replace a vector of numbers by a vector of colors from a palette, such that values correspond to the colors on a smooth gradient.

### Usage

    smoothPalette(x, pal = NULL, max = NULL, min = NULL, n = 9,
      palfunc = NULL, na.color = "white")

### Arguments

`x` | A numeric vector
`pal` | Character vector containing the color gradient onto which the numeric vector `x` will be mapped. By default, a gradient from white to black is generated. If it is a single character value, it will be treated as name of an RColorBrewer palette (see `brewer.pal`).
`max` | Values of `x` larger than `max` will be replaced by `max`
`min` | Values of `x` smaller than `min` will be replaced by `min`
`n` | Number of steps
`palfunc` | Palette function returned by colorRampPalette
`na.color` | NA values will be replaced by that color

### Details

This function is used to map a continues numerical vector on an ordinal character vector, in especially a vector of colors. Color palette can be specified using an RColorBrewer palette name.

### Value

A character vector of the same length as the numeric vector `x`, containing the matching colors.

### Author(s)

January Weiner <january.weiner@gmail.com>

### See Also

`tagcloud`

### Examples

    smoothPalette( 1:3 )
    # will print:
    # "#CCCCCC" "#666666" "#000000"

    smoothPalette( 1:3, pal= "Blues" )
    # will produce:
    # "#F7FBFF" "#6BAED6" "#08306B"

    x <- runif( 100 )
    plot( 1:100, x, col= smoothPalette( x, pal= "BrBG" ), pch= 19 )

[Package tagcloud version 0.6 Index]