hexTapply               package:hexbin               R Documentation

_A_p_p_l_y _f_u_n_c_t_i_o_n _t_o _d_a_t_a _f_r_o_m _e_a_c_h _h_e_x_a_g_o_n _b_i_n.

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

     A wrapper for tapply except that it operates with each hexagon bin
     being the category. The function operates on the data associated
     on the points from each bin.

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

     hexTapply(hbin, dat, FUN = sum, ..., simplify=TRUE)

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

    hbin: a object of class '"hexbin"', typically produced by
          'hexbin(*)'.

     dat: A vector of data the same length as 'hbin@cID'

     FUN: the function to be applied.  In the case of functions like
          '+', '%*%', etc., the function name must be quoted.  If 'FUN'
          is 'NULL', tapply returns a vector which can be used to
          subscript the multi-way array 'tapply' normally produces.

     ...: optional arguments to 'FUN'.

simplify: If 'FALSE', 'tapply' always returns an array of mode
          '"list"'.  If 'TRUE' (the default), then if 'FUN' always
          returns a scalar, 'tapply' returns an array with the mode of
          the scalar.

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

     This function is a wrapper for tapply, except that the cell id is
     always the categorical variable. This function is specifically
     good for adding variables to the cAtt slot of a hexbin object or
     for plotting a third variable in a hexagon plot. See below for
     examples.

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

     Returns a vector of the result of 'FUN' as in 'tapply'. See
     'tapply' for detailed description of output.

_A_u_t_h_o_r(_s):

     Nicholas Lewin-Koh

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

     'tapply','hexbin'

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

       data(NHANES)
       hbin<-hexbin(log(NHANES$Diet.Iron+1),log(NHANES$BMI),xbins=25,IDs=TRUE)
       hvp<-plot(hbin)
       mtrans<-hexTapply(hbin,NHANES$Transferin,median,na.rm=TRUE)
       pushHexport(hvp$plot.vp)
       grid.hexagons(hbin,style='lattice',pen=0,border='red',use.count=FALSE,
     cell.at=mtrans)

       
       

