hist2 {squash} | R Documentation |
Bivariate histogram
Description
Calculate data for a bivariate histogram and (optionally) plot it as a colorgram.
Usage
hist2(x, y = NULL,
nx = 50, ny = nx,
xlim = NULL, ylim = NULL,
xbreaks = NULL, ybreaks = NULL,
plot = TRUE,
xlab = NULL, ylab = NULL, zlab = "Counts",
colFn = heat, breaks = prettyInt, ...)
Arguments
x , y |
Numeric vectors. |
nx , ny |
Approximate number of intervals along x and y axes. |
xlim , ylim |
Limit the range of data points considered. |
xbreaks , ybreaks |
Breakpoints between bins along x and y axes. |
plot |
Plot the histogram? |
xlab , ylab |
Axis labels. |
zlab |
Label for the color key. |
colFn , breaks |
Color key parameters; see |
... |
Further arguments passed to |
Details
Data can be passed to hist2
in any form recognized by xy.coords
(e.g. individual vectors, list, data frame, formula).
Value
Invisibly, a list with components:
x |
Vector of breakpoints along the x-axis. |
y |
Vector of breakpoints along the y-axis. |
z |
Matrix of counts. |
xlab |
A label for the x-axis. |
ylab |
A label for the y-axis. |
zlab |
A label for the color key. |
See Also
hist
, for a standard (univariate) histogram.
hist2d
in the gplots package for another implementation.
The hexbin package, for a hexagonal implementation.
Examples
set.seed(123)
x <- rnorm(10000)
y <- rnorm(10000) + x
hist2(x, y)
## pseudo-log-scale color breaks:
hist2(x, y, breaks = prettyLog, key.args = list(stretch = 4))
## log-scale color breaks; the old way using 'base'
## (notice box removal to make space for the vertical color key)
hist2(x, y, base = 2, key = vkey, nz = 5, bty = 'l')