\HeaderA{densCols}{Colors for Smooth Density Plots}{densCols}
\aliasA{blues9}{densCols}{blues9}
\keyword{dplot}{densCols}
\begin{Description}\relax
\code{densCols} produces a vector containing colors which encode the
local densities at each point in a scatterplot.
\end{Description}
\begin{Usage}
\begin{verbatim}
densCols(x, y = NULL, nbin = 128, bandwidth,
         colramp = colorRampPalette(blues9[-(1:3)]))
blues9
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x, y}] the \code{x} and \code{y} arguments provide the x and y
coordinates of the points.  Any reasonable way of defining the
coordinates is acceptable.  See the function \code{\LinkA{xy.coords}{xy.coords}}
for details.  If supplied separately, they must be of the same length.
\item[\code{nbin}] numeric vector of length one (for both directions) or two
(for x and y separately) specifying the number of equally spaced
grid points for the density estimation; directly used as
\code{gridsize} in \code{\LinkA{bkde2D}{bkde2D}()}.
\item[\code{bandwidth}] numeric vector (length 1 or 2) of smoothing bandwidth(s).
If missing, a more or less useful default is used. \code{bandwidth}
is subsequently passed to function \code{\LinkA{bkde2D}{bkde2D}}.
\item[\code{colramp}] function accepting an integer \code{n} as an argument and
returning \code{n} colors.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{densCols} computes and returns the set of colors that will be
used in plotting.

\code{blues9} is a set of 9 color shades of blue used as the default in
plotting.
\end{Details}
\begin{Value}
\code{densCols} returns a vector of length \code{nrow(x)} that
contains colors to be used in a subsequent scatterplot.  Each color
represents the local density around the corresponding point.
\end{Value}
\begin{Author}\relax
Florian Hahne at FHCRC, originally
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{bkde2D}{bkde2D}} from package \pkg{KernSmooth},
and \code{\LinkA{smoothScatter}{smoothScatter}()} which builds on the same
computations as \code{densCols}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
x1  <- matrix(rnorm(1e3), ncol=2)
x2  <- matrix(rnorm(1e3, mean=3, sd=1.5), ncol=2)
x   <- rbind(x1,x2)

dcols <- densCols(x)
graphics::plot(x, col = dcols, pch=20, main = "n = 1000")
\end{ExampleCode}
\end{Examples}

