assignColors: assignColors

Description Usage Arguments Details Value Examples

View source: R/assignColors.R

Description

Assign to each value in x a color according to the choices of breaks and col.

Usage

1
assignColors(x, breaks = NULL, col = heat.colors, na.col = "white")

Arguments

x

numeric or non-numeric vector

breaks

vector with breaks

col

vector with colors or color function

na.col

color for NA or out-of-range values

Details

Depending if x is a numeric or non-numeric vector colors are assigned to each value.

In case of a numeric vector breaks can be

In case of a non-numeric vector breaks must contain all values which are will get a color. If breaks is not given then a sensible default is choosen: in case of a numeric vector derived from pretty and otherwise all unique values/levels are used.

col can be either be a vector of colors or a function which generates via col(n) a set of n colors. The default is to use heat.colors.

Possible color functions in R packages can be found by vignette('plot.matrix').

Value

vector of color with the same length as x with the attributes breaks the breaks used, col the color coding and na.col the color for NA and out-of-range entries

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## numeric vector
x <- runif(10)
assignColors(x)
# set breaks
assignColors(x, breaks=15)
assignColors(x, breaks=c(0,1))
# set colors
assignColors(x, col=c("red", "green", "blue"))
assignColors(x, col=topo.colors)
# NA and out-of-range
x[5] <- NA
assignColors(x, breaks=seq(0.5, 1, by=0.1), na.col="red")
## logical vector
l <- sample(c(NA, TRUE, FALSE), size=10, replace=TRUE)
assignColors(l)
assignColors(l, breaks=c("FALSE", "TRUE"), col=c("red", "blue"))
## character vector
t <- sample(letters, size=10, replace=TRUE)
assignColors(t)
assignColors(t, col=rainbow(5))

sigbertklinke/plot.matrix documentation built on Dec. 8, 2019, 4:11 p.m.