Compute Hexagon Cell Ids From x and y

DESCRIPTION:
Computes hexagon cell id's corresponding to xy-pairs. Used for partitioning data into hexagonal regions and for computation of statistics for each of these regions. Provides symbol congestion control in maps.

USAGE:
xy2cell(x, y, xbins=30, shape=1, xlim=range(x), ylim=range(y))

REQUIRED ARGUMENTS:
x:
numeric vector. Usually the first (horizontal) coordinate of bivariate data to be binned into hexagonal cells.
y:
numeric vector. Usually the second (vertical) coordinate of bivariate data to be binned.

OPTIONAL ARGUMENTS:
xbins:
number of hexagonal cells partitioning the range of x values.
shape:
height to width ratio for the hexagonal cells.
xlim:
the horizontal limits of the binning region in units of x. By default these are the minimum and maximum values of x.
ylim:
the vertical limits of the binning region in y units. This defaults to the minimum and maximum values of y.

VALUE:
a vector of cell identifiers that can be mapped into the bin centers in data units. This vector will have the same length as x and y. The result also has the following attributes:
xbins:
number of hexagonal cells across the x axis.
shape:
same as the input parameter shape.
xlim:
same as input parameter xlim.
ylim:
same as input parameter ylim.

DETAILS:
The plot shape must be maintained for hexagons to appear with equal sides. Calculations are in single precision.

This function can be used to compute statistics per cell. See the EXAMPLES below for one such instance.


REFERENCES:
Carr, D. B., Olsen, A. R. and White, D. (1992). Hexagon mosaic maps for display of univariate and bivariate geographical data. Cartography and Geographics Information Systems, 19, 228-236.

SEE ALSO:
cell2xy , hexbin , summary.hexbin , plot.hexbin , identify.hexbin, smooth.hexbin , erode.hexbin .

EXAMPLES:
ozone.bin <- hexbin(ozone.xy$x, ozone.xy$y, xbins=8)
ozone.cells <- xy2cell(ozone.xy$x, ozone.xy$y, xbins=8)
# Find the median of each hexagonal cell:
ozone.angle <- tapply(ozone.median,ozone.cells,median)
map(region=c("new york","new jersey","conn","mass"),lty=2)
rayplot(ozone.bin$xcenter,ozone.bin$ycenter,ozone.angle)