hexpolygon              package:hexbin              R Documentation

_H_e_x_a_g_o_n _C_o_o_r_d_i_n_a_t_e_s _a_n_d _P_o_l_y_g_o_n _D_r_a_w_i_n_g

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

     Simple 'low-level' function for computing and drawing hexagons.
     Can be used for 'grid' (package 'grid') or 'traditional' (package
     'graphics') graphics.

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

     hexcoords(dx, dy = NULL, n = 1, sep = NULL)

     hexpolygon(x, y, hexC = hexcoords(dx, dy, n = 1), dx, dy = NULL,
                fill = 1, border = 0, hUnit = "native", ...)

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

   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, 'NULL' doesn't use a separator.

     x,y: numeric vectors of the same length specifying the hexagon
          _centers_ around which to draw.

    hexC: a list as returned from 'hexcoords()'. Its component 'no.sep'
          determines if grid or traditional graphics are used. The
          default (via default of 'hexcoords') is now to use grid
          graphics.

fill,border: passed to 'grid.polygon' (for 'grid').

   hUnit: string or 'NULL' determining in which units (x,y) values are.

     ...: further arguments passed to 'polygon' (for 'graphics').

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

     'hexcoords()' returns a list with components 

     x,y: numeric vectors of length n * 6 (or n * 7 if 'sep' is not
          NULL) specifying the hexagon polygon coordinates (with 'sep'
          appended to each 6-tuple).

  no.sep: a logical indicating if 'sep' was 'NULL'.


     'hexpolygon' returns what its last 'grid.polygon(.)' or
     'polygon(.)' call returns.

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

     Martin Maechler, originally.

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

     'grid.hexagons' which builds on these.

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

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

