library(hexify)
# Generate some data with hex cells
df <- data.frame(lon = c(0, 5, 10), lat = c(45, 46, 45))
result <- hexify(df, lon = "lon", lat = "lat", area = 1000)
# Get polygons as sf object (using HexData)
polys <- cell_to_sf(grid = result)
# Or with explicit parameters
polys <- hexify_cell_to_sf(result@cell_id, resolution = 10, aperture = 3)
# Plot with sf
library(sf)
plot(st_geometry(polys), col = "lightblue", border = "blue")
Run the code above in your browser using DataLab