hexbin                package:hexbin                R Documentation

_B_i_v_a_r_i_a_t_e _B_i_n_n_i_n_g _i_n_t_o _H_e_x_a_g_o_n _C_e_l_l_s

_D_e_s_c_r_i_p_t_i_o_n:

     Creates a '"hexbin"' object.  Basic components are a cell id and a
     count of points falling in each occupied cell.

     Basic methods are 'show()', 'plot()'  and 'summary()', but also
     'erode'.

_U_s_a_g_e:

     hexbin(x, y, xbins = 30, shape = 1,
            xbnds = range(x), ybnds = range(y),
            xlab = NULL, ylab = NULL, IDs = FALSE)

_A_r_g_u_m_e_n_t_s:

    x, y: vectors giving the coordinates of the bivariate data points
          to be binned.  Alternatively a single plotting structure can
          be specified: see 'xy.coords'.  'NA''s are allowed and
          silently omitted.

   xbins: the number of bins partitioning the range of xbnds.

   shape: the _shape_ = yheight/xwidth of the plotting regions.

xbnds, ybnds: horizontal and vertical limits of the binning region in x
          or y units respectively; must be numeric vector of length 2.

xlab, ylab: optional character strings used as labels for 'x' and 'y'. 
          If 'NULL', sensible defaults are used.

     IDs: logical indicating if the individual cell IDs should be
          returned, see also below.

_D_e_t_a_i_l_s:

     Returns counts for non-empty cells only.  The plot shape must be
     maintained for hexagons to appear with equal sides.  Some
     calculations are in single precision.

     Note that when plotting a 'hexbin' object, the 'grid' package is
     used. You must use its graphics (or those from package 'lattice'
     if you know how) to add to such plots.

_V_a_l_u_e:

     an S4 object of class '"hexbin"'. It has the following slots: 

    cell: vector of cell ids that can be mapped into the (x,y) bin
          centers in data units.

   count: vector of counts in the cells.

     xcm: The x center of mass (average of x values) for the cell.

     ycm: The y center of mass (average of y values) for the cell.

   xbins: number of hexagons across the x axis. hexagon inner diameter
          =diff(xbnds)/xbins in x units

   shape: plot shape which is yheight(inches) / xwidth(inches)

   xbnds: x coordinate bounds for binning and plotting

   ybnds: y coordinate bounds for binning and plotting

   dimen: The i and j limits of cnt treated as a matrix cnt[i,j]

       n: number of (non NA) (x,y) points, i.e., 'sum(* @count)'.

  ncells: number of cells, i.e., 'length(* @count)', etc

    call: the function call.

xlab, ylab: character strings to be used as axis labels.

     cID: of class, '"integer or NULL"', only if 'IDs' was true, an
          integer vector of length 'n' where 'cID[i]' is the cell
          number of the i-th original point '(x[i], y[i])'. 
          Consequently, the 'cell' and 'count' slots are the same as
          the 'names' and entries of 'table(cID)', see the example.

_R_e_f_e_r_e_n_c_e_s:

     Carr, D. B. et al. (1987) Scatterplot Matrix Techniques for Large
     N. _JASA_ *83*, 398, 424-436.

_S_e_e _A_l_s_o:

     'hcell2xy' 'gplot.hexbin', 'grid.hexagons', 'grid.hexlegend'.

_E_x_a_m_p_l_e_s:

     set.seed(101)
     x <- rnorm(10000)
     y <- rnorm(10000)
     (bin <- hexbin(x, y))
     ## or
     plot(hexbin(x, y + x*(x+1)/4),
          main = "(X, X(X+1)/4 + Y)  where X,Y ~ rnorm(10000)")

     ## Using plot method for hexbin objects:
     plot(bin, style = "nested.lattice")

     hbi <- hexbin(y ~ x, xbins = 80, IDs= TRUE)
     str(hbi)
     tI <- table(hbi@cID)
     stopifnot(names(tI) == hbi@cell,
                     tI  == hbi@count)

     ## NA's now work too:
     x[runif(6, 0, length(x))] <- NA
     y[runif(7, 0, length(y))] <- NA
     hbN <- hexbin(x,y)
     summary(hbN)

