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 'plot()' (plot.hexbin) and 'summary()'
     (summary.hexbin), but also the functions 'smooth.hexbin' and
     'erode.hexbin'.

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

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

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

       x: a vector of numbers.  The first coordinate of bivariate data
          to be binned.

       y: a vector of numbers.  The second coordinate of bivariate data
          to be binned.

   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.

     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.  The plot shape must be
     maintained for hexagons to appear with equal sides.  Some
     calculations are in single precision.

     Note that when plotting with 'plot.hexbin', the plotting
     parameters are changed during the plot and it returns the changed
     'par' parameters, so to utilize the same plot window one must be
     sure to also use these 'par' values for it to work properly (see
     the use of 'screenpar' in the examples below).

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

     an object of class '"hexbin"'. The list structure typically
     contains the following components: 

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

     cnt: 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

   xbnds: x coordinate bounds for binning and plotting

   ybnds: y coordinate bounds for binning and plotting

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

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

 cell.id: only if 'IDs' was true, an integer vector of length 'n' where
          'cell.id[i]' is the cell number of the i-th original point
          '(x[i], y[i])'.

_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', 'hcell', 'plot.hexbin', 'hboxplot', 'hdiffplot',
     'hmatplot', 'hexagons', 'hex.legend'.

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

     x <- rnorm(10000)
     y <- rnorm(10000)
     bin <- hexbin(x,y)

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

     ## lower resolution binning and overplotting with counts
     bin <- hexbin(x,y,xbins=25)
     screenpar <- plot.hexbin(bin, style="lattice", minarea=1, maxarea=1,
                        density=0, border=TRUE)
     oldpar <- par(screenpar)     # reset graphics to the plot on the screen
     xy <- hcell2xy(bin)
     text(xy$x,xy$y,as.character(bin$cnt),adj=.5,cex=.3)
     points(x,y)       # to show points rather than counts
     par(oldpar)       #reset graphics

     ## Use (and 'check') IDs:
     bin3 <- hexbin(x, y, IDs = TRUE)
     tb <- table(bin3$cell.id)
     stopifnot(bin3$cnt  == c(tb),
               bin3$cell == rownames(tb))

