thinScatter.matrix {scatterPlots}R Documentation

Thinning scatter plot data preserving densities

Description

Thinning scatter plot data preserving densities.

Usage

## S3 method for class 'matrix':
thinScatter(x, nbin=128, size=1, ...)

Arguments

x A numeric Nx2 matrix where each row represent an (x,y) data point.
nbin A integer vector of length two specifying the number of bins along the x and the y axis, respectively. If a single value is given, the same binning is used in both direction.
size Either a double in [0,1] or an integer in (1,nrow(x)). If in [0,1], then the number of returned data points equals size*nrow(x), otherwise size.
... Not used.

Value

Returns an Mx2 matrix containing the thinned (x,y) data points, where M <= N, ordered by their bin density. The following attributes are attached:

density A vector of densities with values in [0,1].
params A list of parameters used.
map A list.

Author(s)

Henrik Bengtsson (http://www.braju.com/R/)

See Also

*smoothScatter().

Examples

# Sample scatter data
n <- 10e3
x <- rnorm(n=n)
y <- rnorm(n=n)
xy <- cbind(x=x, y=sin(x)+y/5)

layout(matrix(1:4, nrow=2, byrow=TRUE))
par(mar=c(5,4,2,1))

# Plot data
plot(xy, pch=1)

# Thin scatter data by subsampling
rhos <- c(1/3, 1/4, 1/6)
for (kk in seq(along=rhos)) {
  xy2 <- thinScatter(xy, size=rhos[kk])
  points(xy2, pch=1, col=kk+1)
  title <- paste(sprintf("%.1f%%", 100*c(1, rhos)), collapse=", ")
  mtext(side=3, line=0, paste("Densities:", title))
}

for (kk in seq(along=rhos)) {
  xy2 <- thinScatter(xy, size=rhos[kk])
  plot(xy2, pch=1, col=kk+1)
  mtext(side=3, line=0, sprintf("Density: %.1f%% [n=%d]", 100*rhos[kk], nrow(xy2)))
}

[Package scatterPlots version 0.0.2 Index]