[R] overriding axis limits in hexbin plot?

Ben Bolker bbolker at gmail.com
Fri Jul 23 16:21:15 CEST 2010


 [cc'd to package maintainer]

  This feels like a fairly straightforward question, so I'm surprised
not to have found an answer so far (RSiteSearch, package help,
vignette ...)

  It seems fairly hard (without some fairly serious hacking) to
hard-code the axis limits in a hexbin plot from the hexbin package.
Here's what I've figured out so far:

  * when you do the hexagonal binning in the first place, you can
specify the x and y ranges (xbnds, ybnds). Fine ... but ...

  * the plot method for 'hexbin' objects (which doesn't have 'xlim' or
'ylim' arguments) calls hexViewport as

   hexViewport(x, offset = unit(legend, "inches"))

  * in the absence of explicit 'xbnds'/'ybnds' arguments, hexViewport does

   xyb <- smartBnds(x)
    hvp at xscale <- xs <- if (is.null(xbnds))
        xyb$xr
    else xbnds
    hvp at yscale <- ys <- if (is.null(ybnds))
        xyb$yr
    else ybnds

  It looks like hexbin:::smartBnds computes x  and y ranges from the
hexagonal cells in
the object, not looking at the xbnds and ybnds slots ...

    There are various ways to change this. If left to my own devices I
will probably hack a version
of the plot method that has explicit xlim and ylim arguments, but I
wanted to (1) check that I wasn't
missing anything obvious and (2) see if the package maintainer would
be interested in a patch ...

   I think hexbin is reasonably widely used (or should be) and this
seems like a common requirement,
so (as I said) I'm surprised it hasn't come up.

  Ben Bolker



More information about the R-help mailing list