File: color.scale.Rd

package info (click to toggle)
r-cran-plotrix 2.9-3-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 960 kB
  • sloc: makefile: 3
file content (63 lines) | stat: -rw-r--r-- 2,610 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
\name{color.scale}
\alias{color.scale}
\title{Turn values into colors.}
\description{Transform numeric values into colors}
\usage{
 color.scale(x,redrange=c(0,1),greenrange=c(0,1),bluerange=c(0,1),
  extremes=NA,na.color=NA,xrange=NULL)
}
\arguments{
 \item{x}{a numeric vector, matrix or data frame}
 \item{redrange,greenrange,bluerange}{color ranges into which 
  to scale \samp{x}}
 \item{extremes}{The colors for the extreme values of \samp{x}.}
 \item{na.color}{The color to use for NA values of \samp{x}.}
 \item{xrange}{An explicit range to use in the transformation.}
}
\details{
 \samp{color.scale} calculates a sequence of colors by a linear
  transformation of the numeric values supplied into the ranges 
  for red, green and blue. If only one number is supplied for a
  color range, that color remains constant for all values of \samp{x}.
  If more than two values are supplied, the \samp{x} values will be
  split into equal ranges (one less than the number of colors) and 
  the transformation carried out on each range. Values for a color
  range must be between 0 and 1.
  
  If \samp{extremes} is not NA, the ranges will be calculated from
  its values using \samp{col2rgb}, even if ranges are also supplied.
  \samp{extremes} allows the user to just pass the extreme color values
  in any format that \samp{col2rgb} will accept.

  If the user wants to specify a range of values with \samp{xrange},
  it must at least include the range of x values. This can be useful
  when there is a notional range like 0-100% that the values do not
  cover, or when several series of values with different ranges are
  to be assigned the same color scale.

  The user may not want the color scheme to be continuous across some
  critical point, often zero. In this case, color scale can be called
  separately for the values below and above zero. See the second example
  for \samp{color2D.matplot}.
}
\note{
 The function is useful for highlighting a numeric dimension or adding
 an extra "dimension" to a plot.

 There are quite a few R functions that transform numeric values into
 colors or produce colors that can be used to represent values. Two
 packages that might be of interest are \pkg{RColorBrewer} and 
 \pkg{colourschemes}.
}
\value{A vector or matrix of hexadecimal color values.}
\author{Jim Lemon}
\seealso{\link{rescale}, \link{col2rgb}, \link{smoothColors}}
\examples{
 # go from green through yellow to red with no blue
 x<-rnorm(20)
 y<-rnorm(20)
 # use y for the color scale
 plot(x,y,col=color.scale(y,c(0,1,1),c(1,1,0),0),main="Color scale plot",
  pch=16,cex=2)
}
\keyword{misc}