Learn R Programming

ggvfields (version 1.0.0)

grid_hex: Generate a Hexagonal Lattice

Description

This function generates a hexagonal lattice of points within the given x and y limits, using a specified hexagon diameter. The diameter is 2 times the distance between adjacent x (and y) values, see examples.

Usage

grid_hex(xlim, ylim, d)

Value

A data frame with two columns, x and y, containing the coordinates of the hexagonal grid points.

Arguments

xlim

A numeric vector of length 2 specifying the x-axis limits.

ylim

A numeric vector of length 2 specifying the y-axis limits.

d

A numeric value specifying the hexagon diameter.

Examples

Run this code

xlim <- c(-1, 1)
ylim <- c(-1, 0)

grid <- grid_hex(xlim, ylim, .25)

head( grid )
str( grid )
plot( grid, asp = 1 )

diff(sort(unique(grid$x)))


Run the code above in your browser using DataLab