hmatplot               package:hexbin               R Documentation

_D_r_a_w _M_a_t_r_i_x _o_f _2-_D _B_o_x_p_l_o_t_s _F_o_r _H_e_x_b_i_n _O_b_j_e_c_t_s

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

     Produces a matrix of 2-D boxplots for hexbin objects classified by
     one or two factors.  The function also interposes difference plots
     between adjacent boxplots.

     This is a two-way (or one-way)  multiple panel plot.  The panels
     with odd row and column numbers show 2-D boxplots produce by
     hboxplot(). Panels between boxplots show the difference of
     adjacent 2-D boxplots using see hdiffplot().

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

     hmatplot(namemat, rlabels, clabels,
              brd = c(0.5, 0.7, 0.7, 0.5),
              mai = rep(0.4, 4), unzoom = 1.04, cex = 1.5,
              border = list(hbox=c(FALSE,FALSE),hdiff=rep("white",6)),
              pen = list( hbox = c(2, 3),hdiff = 2:7 ),
              density = c(-1, -1, -1, 0, 0, 0), size = 0.06, lwd = 2)

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

 namemat: a matrix of  hexbin object names

 rlabels: row labels for the matrix

 clabels: column labels for the matrix

     brd: border space for the plot.

     mai: margin for individual panels, (must be smaller that brd)

  unzoom: plot limit expansion factor when xbnds is missing

     cex: character expansion size for labels

  border: a list with elements "hbox" which are the arguments to
          hboxplot() and "hdiff" which are arguments to hdiffplot()

     pen: a list with elements "hbox" which are the arguments to
          hboxplot() and "hdiff" which are arguments to hdiffplot()

 density: argument to hdiffplot()

    size: arrow tip size in hdiffplot()

     lwd: arrow thinkness in hdiffplot()

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

     Namemat is a matrix of hexbin object names corresponding to
     classification by two factors.  Typically the hexbin objects are
     the result of identically scaled binning, smoothing and erosion. 
     However, data variations lead to different contours in the
     boxplots.  This function determines global zoom-in scaling that
     covers all of hboxplot() results.

     Be careful that rlabels and clabels correspond to the bin objects.

     hboxplot() uses pen 2 median and pen 3 as the default. hdiffplot()
     used pens 4 to 9  for the respective cells as the default.

     Suggested polygon colors #000 #000 #AAA #58F #FFF #F11 #FFF #FFF.
     Suggested background: white Suggested lines : black

     The default turns off the polygon fill for the medians in
     hdiffplot.

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

list(xbnds,ybnds,xsize,ysize,plot.par): xbnds and ybnds given the
          ranges for plotting a single plot in data units. xsize and
          ysize give the size of a single plot in inches. plot.par is a
          list of lists, where each list is the plot parameters of the
          hboxplots, and the hdiffplots for rows and columns
          respectively

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

     Dan Carr <dcarr@voxel.galaxy.gmu.edu> ported by Nicholas Lewin-Koh
     <kohnicho@comp.nus.edu.sg>

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

     see in 'hexagons'.

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

     'hexbin', 'smooth.hexbin', 'erode.hexbin', 'hcell2xy',  'hcell',
     'plot.hexbin', 'hboxplot', 'hmatplot', 'hexagons', 'hex.legend'

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

     # nhanes data set
     # remove missing data, and extract variable of interest
     # make this so you can do data(nh)

     data(NHANES)# pretty large data set!
     good <- !(is.na(NHANES$Albumin) | is.na(NHANES$Transferin))
     NH.vars <- NHANES[good, c("Age","Sex","Albumin","Transferin")]

     # extract dependent variables and find  ranges for global binning
     x <- NH.vars[,"Albumin"]
     rx <- range(x)
     y <- NH.vars[,"Transferin"]
     ry <- range(y)

     # define index for the twoway layout
     age <- cut(NH.vars$Age,c(1,45,65,200))
     sex <- NH.vars$Sex
     subs <- tapply(age,list(age,sex))

     #  bivariate bins for each factor combination
     for (i in 1:length(unique(subs))) {
       good <- subs==i
       assign(paste("nam",i,sep=""),
              erode.hexbin(hexbin(x[good],y[good],xbins=23,xbnds=rx,ybnds=ry)))
     }

     # define arguments to hmatplot
     nam <- matrix(paste("nam",1:6,sep=""),ncol=3,byrow=TRUE)
     rlabels <-c("Females","Males")
     clabels  <- c("Age <= 45","45 < Age <= 65","Age > 65")
     zoom <- hmatplot(nam,rlabels,clabels,border=list(hbox=c("black","white"),hdiff=rep("white",6)))

     # enlarged legend
     hboxplot(nam1, zoom$xbnds,zoom$ybnds, reshape=TRUE, xlab= "Albumin (mg/dl)",
              ylab="Transferrin Sat. (\)", cex=1.2)

     str(lapply(NHANES, function(x){if(
     is.numeric(x)){cat(names(x),": NA ", sum(is.na(x))," Obs: ",sum(!is.na(x)),"\n")}}))

