Skip to content
Prev 66831 / 398506 Next

hexbin and grid - input data values as coordinates

Hi
Adaikalavan Ramasamy wrote:
gplot.hexbin() returns the viewports it used to produce the plot and the 
legend.  Here's an example of annotating the plot ...

  # capture the viewports returned
  vps <- plot( hexbin( x, y ), style = "nested.lattice")
  # push the viewport corresponding to the plot
  # this is actually a hexViewport rather than a plain grid viewport
  # so you use pushHexport rather than grid's pushViewport
  pushHexport(vps$plot.vp)
  # use "native" coordinates to draw relative to the axis scales
  grid.move.to(-2, -10, default.units="native")
  grid.line.to(2, 10, default.units="native",
               gp=gpar(col="yellow", lwd=3))
  # tidy up
  popViewport()

There's another annotation example at the bottom of the help page for 
gplot.hexbin

A grid.abline() function would obviously be a useful addition.  Must 
find where I put my todo list ...

Paul