Hexbin Plot

DESCRIPTION:

Creates a hexbin plot with optional (Trellis) conditioning for two numeric variables.

USAGE:

hexplot(formula, data=sys.parent(), panel=panel.hexbin, prepanel=prepanel.hexbin, 
        xbins=30, shape=1, scales=list(), endpoints=range(x.value, na.rm = T), 
        shingle.args=list(), shingle.fun="equal.count", ..., xlab=val$xlab, 
        ylab=val$ylab, col.regions=trellis.par.get("regions")$col, colorkey, 
        maxcount, xlim=range(na.rm = T, x), ylim=range(na.rm = T, y), 
        call=match.call(), groups=NULL, subset=T)

REQUIRED ARGUMENTS:

formula
a formula in the form y ~ x | g1 * g2 * ... however the given variables g1, g2, ... may be omitted. The x and y values in formula should both be numeric.

OPTIONAL ARGUMENTS:

data
data frame, list or bdFrame in which to find the objects mentioned in formula. If this argument is a bdFrame then a bigdata version of the function is called. When the data= argument is included, objects in formula are not searched for in the frame of the caller. Thus, if you write a function that calls a Trellis routine and supplies the data= argument, no objects defined in your function will be accessible, nor will arguments to your function be accessible. Regardless of the data= argument, objects are always accessible if they are on the database search list.
xbins
number of bins partitioning the range of the values of x. Same as the input value for hexbin. Hexagons inner diameter equals diff(xlim)/xbins in x units.
shape
height to width ratio for the resulting plotting region. This parameter is used in determining the number of bins in the y-direction given xbins, the number of bins in the x-direction. The default value shape=1 makes the hexagons appear equal-sided when plotted.
endpoints
endpoints of intervals used in constructing shingles from numeric given variables.
shingle.args
named list of arguments to shingle.fun.
shingle.fun
function for automatically converting a numeric variable specified in the given part of the formula to a shingle in preparation to conditioning on that variable.
...
additional named Trellis arguments listed separately under trellis.args and additional named arguments which are passed to the panel function, panel.hexplot by default.
col.regions
vector of integers or character strings representing the colors. These correspond to the colors in the graphics device colormap that are used to color the hexagons. Different color devices have more or less adequate colormaps. Using a device defined with a call to trellis.device will ensure that a colormap close to adequate is used. See the DETAILS section for ways to select other colormaps.
colorkey
a list produced by by the internal function, color.key, for creating the color key (or legend) associated with the hexplot. This list is returned in the resulting Trellis object and may be used in subsequent hexplot calls to create comparable color keys.
maxcount
a numeric value. The value is mapped to the last color. This may be useful to make several hexplots with the same mapping of count to color.
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:

an object of class "trellis", which is automatically plotted by print.trellis.

SIDE EFFECTS:

Produces a plot of the hexagons created by hexbin as determined by formula , data and other arguments controlling hexbinning. Includes a color key or legend.

DETAILS:

A way to try different colormaps on Windows is by using the Options pull down menu in your graphics device driver and typing in your own color map in the Polygons widget. For smoothly varying colormaps, you may want to copy the Image colors into the Polygons slot.

On Unix systems see the helpfile for heat.colors, for example, to see how to create different colormaps.

REFERENCES:

Carr, D. B., Littlefield, R. J., Nicholson, W. L. and Littlefield, J. S. (1987). Scatterplot matrix techniques for large N. Journal American Statistical Association 83, 424-436.

Carr, D. B. (1991). Looking at large data sets using binned data plots. In Computing and Graphics in Statistics. A. Buja and P. Tukey, eds. Springer-Verlag, New York. pp. 7-39.

SEE ALSO:

, , , ,

EXAMPLES:

# no conditioning
x = rnorm(10000)
y = rnorm(10000)
hexplot(y ~ x)
# with conditioning
grp = rep(1:4, 2500)
hexplot(y ~ x | grp)
# setting the color regions
hexplot(y ~ x | grp, col.regions = heat.colors(10))
# different group of colors using hsv()
hexplot(y ~ x | grp, col.regions = hsv(h=seq(0.1, 0.9, length=16), s=0.75, v=1))
# converting a numeric grouping variable
numgrp = runif(10000)
hexplot(y ~ x | equal.count(numgrp), col.regions = heat.colors(10))
# specifying the number of hexbins
hexplot(y ~ x | equal.count(numgrp), col.regions = heat.colors(10), xbins = 50)