'two-point Voronoi diagram
I have a dataset containing pair of points in a 2D space (X,Y,nnX,nnY columns). I want to create a Voronoi diagram using these pairs of points such that each each partition will contain exactly two points. Then color the partitions using the columns wall_to_wall_dist column.
How can I do this in ggplot?
I did some research and it seems there is something called two-point Voronoi diagram or partial Voronio diagrams in theory but couldn't figure out how to do it in practice.
Here is a tiny part of the dataset (~100,000 rows) that I'm using:
structure(list(ID = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), X = c(318L, 317L, 316L,
315L, 314L, 313L, 312L, 311L, 310L, 309L, 1273L, 1272L, 1271L,
1270L, 1269L, 1268L, 1267L, 1266L, 1265L, 1264L), Y = c(1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L), t = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1), uid = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 1271L, 1272L, 1273L, 1274L, 1275L, 1276L, 1277L, 1278L,
1279L, 1280L), nnX = c(1264L, 1264L, 1264L, 1264L, 1264L, 1264L,
1264L, 1264L, 1264L, 1264L, 318L, 318L, 318L, 318L, 318L, 318L,
318L, 318L, 318L, 318L), nnY = c(10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
wall_to_wall_dist = c(946.042810870629, 947.033790315847,
948.025843529595, 949.018967144493, 950.013157803617, 951.008412160481,
952.004726879021, 953.002098633576, 954.000524108871, 955,
955, 954.000524108871, 953.002098633576, 952.004726879021,
951.008412160481, 950.013157803617, 949.018967144493, 948.025843529595,
947.033790315847, 946.042810870629)), row.names = c(NA, -20L
), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x7fce30813ce0>)
X,Yrepresent the location of the boundary pointsnnX, nnYrepresent the nearest neighbour boundary point that is not on the same rectangle, seewall_to_wall_distis the distance betweenX,YandnnX, nnYIDa unique id for each rectangleuida unique id for each boundary point, regardless of the rectangle they are on
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
