hmatplot {hexbin}R Documentation

Draw Matrix of 2-D Boxplots For Hexbin Objects

Description

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().

Usage

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

Arguments

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, pen, density each a list with two components hbox to be used as argument to hboxplot() and component hdiff to be used in calling hdiffplot().
size, lwd arrow tip size and arrow thickness in hdiffplot().

Details

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.

Value

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

Author(s)

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

References

see in hexagons.

See Also

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

Examples

## 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")}}))

[Package hexbin version 1.0.10 Index]