hist2: Bivariate histogram

Description Usage Arguments Details Value See Also Examples

View source: R/squash.R

Description

Calculate data for a bivariate histogram and (optionally) plot it as a colorgram.

Usage

1
2
3
4
5
6
7
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 makecmap.

...

Further arguments passed to colorgram.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
  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')

squash documentation built on Feb. 20, 2020, 9:08 a.m.