smoothScatter  R Documentation 
smoothScatter
produces a smoothed color density
representation of a scatterplot, obtained through a (2D) kernel
density estimate.
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 
the 
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

bandwidth 
numeric vector (length 1 or 2) of smoothing bandwidth(s).
If missing, a more or less useful default is used. 
colramp 
function accepting an integer 
nrpoints 
number of points to be superimposed on the density
image. The first 
ret.selection 

pch, cex, col 
arguments passed to 
transformation 
function mapping the density scale to the color scale. 
postPlotHook 
either 
xlab, ylab 
character strings to be used as axis labels, passed
to 
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.
See the examples for how to use this function together with
pairs
.
If ret.selection
is true, a vector of integers of length
nrpoints
(or smaller, if there are less finite points inside
xlim
and ylim
) with the indices of the lowdensity
points drawn, ordered with lowest density first.
Florian Hahne at FHCRC, originally
bkde2D
from package KernSmooth;
densCols
which uses the same smoothing computations and
blues9
in package grDevices.
scatter.smooth
adds a loess
regression smoother to a scatter plot.
## A largish data set n < 10000 x1 < matrix(rnorm(n), ncol = 2) x2 < matrix(rnorm(n, mean = 3, sd = 1.5), ncol = 2) x < rbind(x1, x2) oldpar < par(mfrow = c(2, 2), mar=.1+c(3,3,1,1), mgp = c(1.5, 0.5, 0)) smoothScatter(x, nrpoints = 0) smoothScatter(x) ## a different color scheme: Lab.palette < colorRampPalette(c("blue", "orange", "red"), space = "Lab") i.s < smoothScatter(x, colramp = Lab.palette, ## pch=NA: do not draw them nrpoints = 250, ret.selection=TRUE) ## label the 20 very lowestdensity points,the "outliers" (with obs.number): i.20 < i.s[1:20] text(x[i.20,], labels = i.20, cex= 0.75) ## somewhat similar, using identical smoothing computations, ## but considerably *less* efficient for really large data: plot(x, col = densCols(x), pch = 20) ## use with pairs: par(mfrow = c(1, 1)) y < matrix(rnorm(40000), ncol = 4) + 3*rnorm(10000) y[, c(2,4)] < y[, c(2,4)] pairs(y, panel = function(...) smoothScatter(..., nrpoints = 0, add = TRUE), gap = 0.2) par(oldpar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.