Skip to content

Instantly share code, notes, and snippets.

@vankesteren
Created March 26, 2020 09:23
Show Gist options
  • Save vankesteren/0b3aa2cff94f72dd6d78b1c3c8241f5e to your computer and use it in GitHub Desktop.
Save vankesteren/0b3aa2cff94f72dd6d78b1c3c8241f5e to your computer and use it in GitHub Desktop.
Delaunay triangulation and voronoi tesselation
library(deldir)
library(ggplot2)
library(firatheme)
N <- 40
dat <- matrix(rnorm(N*2), N)
dat <- dat %*% chol(matrix(c(1, 0, 0, 1.5), 2)) %*% chol(solve(cov(dat)))
dat2 <- deldir(dat[,1], dat[,2])
dat1 <- data.frame(dat)
colnames(dat1) <- c("x1", "y1")
ggplot(dat2$delsgs, aes(x = x1, y = y1)) +
geom_segment(aes(xend = x2, yend = y2),size = 0.5, colour = "#99DA99") +
geom_point(data = dat1, colour = "#9999DA") +
geom_segment(aes(xend = x2, yend = y2), data = dat2$dirsgs, colour = "#DA9999") +
theme_void() +
coord_fixed()
@vankesteren
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment