-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvr_complex.R
More file actions
27 lines (27 loc) · 785 Bytes
/
vr_complex.R
File metadata and controls
27 lines (27 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
vr_complex <- function(X, delta) {
colnames(X)[1:2] <- c("x", "y")
p <- ggplot(X) +
ggforce::geom_circle(
aes(x0 = x, y0 = y, r = delta / 2),
fill = "#56B4E9",
color = "transparent",
alpha = 0.3
)
# Draw lines between all pairs of points less than delta apart
d <- dist(X[, 1:2]) |>
as.matrix() |>
as.data.frame() |>
mutate(row = 1:NROW(X)) |>
tidyr::pivot_longer(1:NROW(X), names_to = "col", values_to = "d") |>
dplyr::filter(row < col, d < delta)
d <- d |>
mutate(
x = X[row, ]$x,
y = X[row, ]$y,
xend = X[col, ]$x,
yend = X[col, ]$y
)
p +
geom_segment(data = d, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_point(data = X, aes(x = x, y = y), size = 2, col = "#b14c14")
}