I'm using the deldir
package to calculate the Voronoi projection of a set of coordinates.
This working great, and I've been able to construct the plot, but I need to relate the calculated points back to the original data set that has additional metadata for each coordinate pair.
Basically, I need a polygon ID that I can match back to my original data. So for example if coordinate pair #1 is projected as a five-sided polygon, I need to assign polygon ID = 1 to each of those five line segments so I can merge in the metadata.
Example with dummy data:
require(deldir)
set.seed(21)
x <- rnorm(500, 0, 1.5)
y <- rnorm(500, 0, 1)
df1 <- data.frame(x,y,ID=seq(1,500,1))
vtess <- deldir(df1$x, df1$y)
So for df1[1,]
, I need to know every value that was generated in vtess
.
The ID for df1[1,]
= 1, so I'm trying to create a column where vtess$polygonID
= 1 for every segment generated by df1[1,]
and so on.
Any help would be fantastic