\HeaderA{Palettes}{Color Palettes}{Palettes}
\aliasA{cm.colors}{Palettes}{cm.colors}
\aliasA{heat.colors}{Palettes}{heat.colors}
\aliasA{rainbow}{Palettes}{rainbow}
\aliasA{terrain.colors}{Palettes}{terrain.colors}
\aliasA{topo.colors}{Palettes}{topo.colors}
\keyword{color}{Palettes}
\keyword{dplot}{Palettes}
\begin{Description}\relax
Create a vector of \code{n} \dQuote{contiguous} colors.
\end{Description}
\begin{Usage}
\begin{verbatim}
rainbow(n, s = 1, v = 1, start = 0, end = max(1,n - 1)/n, gamma = 1)
heat.colors(n)
terrain.colors(n)
topo.colors(n)
cm.colors(n)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{n}] the number of colors (\eqn{\ge 1}{>= 1}) to be in the
palette.
\item[\code{s,v}] the \dQuote{saturation} and \dQuote{value} to be used
to complete the HSV color descriptions.
\item[\code{start}] the (corrected) hue in [0,1] at which the rainbow
begins.
\item[\code{end}] the (corrected) hue in [0,1] at which the rainbow ends.
\item[\code{gamma}] the gamma correction, see argument \code{gamma} in
\code{\LinkA{hsv}{hsv}}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Conceptually, all of these functions actually use (parts of) a line
cut out of the 3-dimensional color space, parametrized by
\code{\LinkA{hsv}{hsv}(h,s,v, gamma)}, where \code{gamma}\eqn{=1}{} for the
\emph{foo}\code{.colors} function, and hence,
equispaced hues in RGB space tend to cluster at
the red, green and blue primaries.

Some applications such as contouring require a palette
of colors which do not \dQuote{wrap around} to give a final
color close to the starting one.

With \code{rainbow}, the parameters \code{start} and \code{end} can be used
to specify particular subranges of hues.
The following values can be used when generating such a subrange:
red=0, yellow=\eqn{\frac 1 6}{1/6}, green=\eqn{\frac 2 6}{2/6},
cyan=\eqn{\frac 3 6}{3/6}, blue=\eqn{\frac 4 6}{4/6}
and magenta=\eqn{\frac 5 6}{5/6}.
\end{Details}
\begin{Value}
A character vector, \code{cv}, of color names.  This can be used
either to create a user--defined color palette for subsequent
graphics by \code{\LinkA{palette}{palette}(cv)}, a \code{col=} specification
in graphics functions or in \code{par}.
\end{Value}
\begin{SeeAlso}\relax
\code{\LinkA{colors}{colors}}, \code{\LinkA{palette}{palette}}, \code{\LinkA{hsv}{hsv}},
\code{\LinkA{hcl}{hcl}}, \code{\LinkA{rgb}{rgb}}, \code{\LinkA{gray}{gray}} and
\code{\LinkA{col2rgb}{col2rgb}} for translating to RGB numbers.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
require(graphics)
# A Color Wheel
pie(rep(1,12), col=rainbow(12))

##------ Some palettes ------------
demo.pal <-
  function(n, border = if (n<32) "light gray" else NA,
           main = paste("color palettes;  n=",n),
           ch.col = c("rainbow(n, start=.7, end=.1)", "heat.colors(n)",
                      "terrain.colors(n)", "topo.colors(n)",
                      "cm.colors(n)"))
{
    nt <- length(ch.col)
    i <- 1:n; j <- n / nt; d <- j/6; dy <- 2*d
    plot(i,i+d, type="n", yaxt="n", ylab="", main=main)
    for (k in 1:nt) {
        rect(i-.5, (k-1)*j+ dy, i+.4, k*j,
             col = eval(parse(text=ch.col[k])), border = border)
        text(2*j,  k * j +dy/4, ch.col[k])
    }
}
n <- if(.Device == "postscript") 64 else 16
     # Since for screen, larger n may give color allocation problem
demo.pal(n)
\end{ExampleCode}
\end{Examples}

