Hexagon Coordinates and Polygon Drawing
Description
Simple ‘lowlevel’ function for computing and drawing hexagons. Can be used for ‘grid’ (package grid) or ‘traditional’ (package graphics) graphics.
Usage
1 2 3 4 
Arguments
dx,dy 
horizontal and vertical width of the hexagon(s). 
n 
number of hexagon “repeats”. 
sep 
separator value to be put between coordinates of different
hexagons. The default, 
x,y 
numeric vectors of the same length specifying the hexagon centers around which to draw. 
hexC 
a list as returned from 
fill,border 
passed to 
hUnit 
string or 
... 
further arguments passed to 
Value
hexcoords()
returns a list with components
x,y 
numeric vectors of length n * 6 (or
n * 7 if 
no.sep 
a logical indicating if 
hexpolygon
returns what its last grid.polygon(.)
or polygon(.)
call returns.
Author(s)
Martin Maechler, originally.
See Also
grid.hexagons
which builds on these.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25  str(hexcoords(1, sep = NA)) # multiple of (6 + 1)
str(hexcoords(1, sep = NULL))# no separator > multiple of 6
## hexpolygon()s:
x < runif(20, 2, 2)
y < x + rnorm(20)
## 1) traditional 'graphics'
plot(x,y, asp = 1, "plot() + hexpolygon()")
hexpolygon(x,y, dx = 0.1, density = 25, col = 2, lwd = 1.5)
## 2) "grid" :
addBit < function(bnds, f = 0.05) bnds + c(f, f) * diff(bnds)
sc < addBit(rxy < range(x,y))# same extents (cheating asp=1)
library("grid")
grid.newpage()
pushViewport(plotViewport(.1+c(4,4,2,1), xscale = sc, yscale = sc))
grid.rect()
grid.xaxis()
grid.yaxis()
grid.points(x,y)
hexpolygon(x,y, hexcoords(dx = 0.1, sep=NULL), border = "blue", fill=NA)
popViewport()
