Scatterplots with Smoothed Densities Color Representation
smoothScatter produces a smoothed color density
representation of a scatterplot, obtained through a (2D) kernel
smoothScatter(x, y = NULL, nbin = 128, bandwidth, colramp = colorRampPalette(c("white", blues9)), nrpoints = 100, ret.selection = FALSE, pch = ".", cex = 1, col = "black", transformation = function(x) x^.25, postPlotHook = box, xlab = NULL, ylab = NULL, xlim, ylim, xaxs = par("xaxs"), yaxs = par("yaxs"), ...)
- x, y
yarguments provide the x and y coordinates for the plot. Any reasonable way of defining the coordinates is acceptable. See the function
xy.coordsfor details. If supplied separately, they must be of the same length.
- 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
- numeric vector (length 1 or 2) of smoothing bandwidth(s).
If missing, a more or less useful default is used.
bandwidthis subsequently passed to function
- function accepting an integer
nas an argument and returning
- number of points to be superimposed on the density
image. The first
nrpointspoints from those areas of lowest regional densities will be plotted. Adding points to the plot allows for the identification of outliers. If all points are to be plotted, choose
nrpoints = Inf.
logicalindicating to return the ordered indices of “low density” points if
nrpoints > 0.
- pch, cex, col
- arguments passed to
nrpoints > 0: point symbol, character expansion factor and color, see also
- function mapping the density scale to the color scale.
NULLor a function which will be called (with no arguments) after
- xlab, ylab
- character strings to be used as axis labels, passed
- xlim, ylim
- numeric vectors of length 2 specifying axis limits.
- xaxs, yaxs, …
- further arguments passed to
smoothScatter produces a smoothed version of a scatter plot.
Two dimensional (kernel density) smoothing is performed by
bkde2D from package KernSmooth">https://CRAN.R-project.org/package=KernSmooth.
See the examples for how to use this function together with
ret.selection is true, a vector of integers of length
nrpoints (or smaller, if there are less finite points inside
ylim) with the indices of the low-density
points drawn, ordered with lowest density first.
bkde2D from package KernSmooth">https://CRAN.R-project.org/package=KernSmooth;
densCols which uses the same smoothing computations and
blues9 in package grDevices.
scatter.smooth adds a
regression smoother to a scatter plot.