I am trying to find the 'nearest neighbors' for the Voronoi graph elements, in other words, the elements which share a common boundary. Is there an implemented way to do it in R. I tried follow the example from here (https://flowingdata.com/2016/04/12/voronoi-diagram-and-delaunay-triangulation-in-r/) and use the deldir
package which helps with estabishing the boundaries:
set.seed(369)
x <- rnorm(50, 0, 1.5)
y <- rnorm(50, 0, 1)
library(deldir)
dta <- deldir(x, y)
plot(x, y, type = "n", asp=1)
points(x, y, pch = 20, col = "red", cex = 0.75)
plot(dta, wlines = "tess", wpoints = "none", number = FALSE, add = TRUE, lty = 1)
How can I find the common boundary neighbours? I there a way to find second degree neighbours (elements that don't share a boundary, but do share a common neighbour)?
Some helpers:
We can turn the
deldir
object into polygons with this function:Your data:
Make the polygons:
We'll need this to show the ID #'s in the centroid position:
Plot it for a visual reference:
Use
gTouches()
for ones that touch:You should be able to turn this into node pairs and use n-away graph algorithms for the second part of your question. Or, open a new question.