Skip to content

Instantly share code, notes, and snippets.

@chichacha
Created December 23, 2018 07:35
Show Gist options
  • Save chichacha/e8df902b78db6e6761dd9b2bc6f3b85f to your computer and use it in GitHub Desktop.
Save chichacha/e8df902b78db6e6761dd9b2bc6f3b85f to your computer and use it in GitHub Desktop.
Circle Packing + Delaunay Triangulation
library(tidyverse)
library(deldir)
library(packcircles)
packing <- circleProgressiveLayout(x=runif(1000)) %>% mutate(id=row_number())
data_gg <- circleLayoutVertices(packing, npoints = 36) %>%
inner_join(packing %>% select(id,radius), by=c("id"))
dxy1 <- deldir(packing$x, packing$y)
dxy1$delsgs %>% ggplot(aes(x=x1,y=y1)) +
geom_polygon(data=data_gg, aes(x=x,y=y,group=id,fill=radius), size=0.1) +
geom_segment(aes(xend=x2, yend=y2), size=0.9, color="#ffffffde") +
theme_void() +
coord_fixed(xlim=range(packing$x)*0.8, ylim=range(packing$y)*0.45) +
scale_fill_viridis_c(guide="none", option="magma", end=0.8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment