# create a grid
hex <- hexagrid(2, sf=TRUE)
# an example shape
shape <- paste0("F", c(4, 5, 11, 13, 15, 21, 24, 26, 32, 33, 34, 35, 36))
# visualize basic grid
plot(hex)
gridlabs(hex)
# visualize the shape
plot(hex, shape, col="#FF000055", add=TRUE)
# calculate holes
ho <- holes(x=hex, y=shape)
# plot both holes
plot(hex, names(ho[ho==1]), add=TRUE, col="#00FF0055")
plot(hex, names(ho[ho==2]), add=TRUE, col="#0000FF55")
Run the code above in your browser using DataLab