Minimum spanning trees #203
Unanswered
francescmolne
asked this question in
Q&A
Replies: 1 comment
-
I think so, example added below: library(tidyverse)
#> Warning: package 'tibble' was built under R version 4.0.5
#> Warning: package 'tidyr' was built under R version 4.0.5
#> Warning: package 'readr' was built under R version 4.0.3
#> Warning: package 'dplyr' was built under R version 4.0.3
library(sf)
#> Warning: package 'sf' was built under R version 4.0.5
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(sfnetworks)
#> Warning: package 'sfnetworks' was built under R version 4.0.5
#> Registered S3 method overwritten by 'spatstat.geom':
#> method from
#> print.boxx cli
library(igraph)
#> Warning: package 'igraph' was built under R version 4.0.3
#>
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:dplyr':
#>
#> as_data_frame, groups, union
#> The following objects are masked from 'package:purrr':
#>
#> compose, simplify
#> The following object is masked from 'package:tidyr':
#>
#> crossing
#> The following object is masked from 'package:tibble':
#>
#> as_data_frame
#> The following objects are masked from 'package:stats':
#>
#> decompose, spectrum
#> The following object is masked from 'package:base':
#>
#> union
library(tidygraph)
#>
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:igraph':
#>
#> groups
#> The following object is masked from 'package:stats':
#>
#> filter
net <- roxel %>%
st_transform(5683) %>%
as_sfnetwork() %>%
activate(edges) %>%
mutate(rn = row_number())
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
minst <- mst(net) %>%
as_sfnetwork() %>%
activate(edges) %>%
left_join(net %>%
activate(edges) %>%
st_as_sf(),by = "rn") %>%
st_as_sf()
#> Checking if spatial network structure is valid...
#> Spatial network structure is valid
net %>%
activate(nodes) %>%
st_as_sf() %>%
ggplot() +
geom_sf() +
geom_sf(data = net %>%
activate(edges) %>%
st_as_sf()) +
geom_sf(data = minst, color = "red") Created on 2022-02-02 by the reprex package (v0.3.0) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, is it possible to create minimum spanning trees (mst() function in igraph)?
Many thanks!
Beta Was this translation helpful? Give feedback.
All reactions