Skip to content

Instantly share code, notes, and snippets.

@idshklein
Created November 11, 2021 18:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idshklein/1556f9a7b49a21d65692e01bbe62e99e to your computer and use it in GitHub Desktop.
Save idshklein/1556f9a7b49a21d65692e01bbe62e99e to your computer and use it in GitHub Desktop.
library(tidyverse)
library(sf)
library(sfnetworks)
library(cluster)
library(crsuggest)
library(tidygraph)
library(ggspatial)
# library(gganimate)
crsuggest::suggest_crs(roxel)
net <- roxel %>%
st_transform(5683) %>%
as_sfnetwork() %>%
filter(group_components()==1)
mat <- net %>%
st_network_cost()
dianamat <- diana(mat)
states <- map(1:20,function(x){
clus <- dianamat %>% cutree(x)
net %>%
mutate(clus = clus, nclus = x,rn = row_number()) %>%
st_as_sf()
}) %>%
bind_rows()
states %>%
filter(nclus < 11) %>%
ggplot(aes(group = rn,color = factor(clus))) +
annotation_map_tile(zoom = 14) +
geom_sf() +
facet_wrap(~nclus)
# transition_states(nclus)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment