class: center, middle, inverse, title-slide # Tidy Geospatial Networks in R ## Introducing the
sfnetworks
package ### Lucas van der Meer, Lorena Abad, Andrea Gilardi, Robin Lovelace ### 2020-06-16 --- class: center, middle <STYLE type='text/css' scoped> PRE.fansi SPAN {padding-top: .25em; padding-bottom: .25em}; </STYLE> ### Want to follow along? Get the slides here: https://sfnetworks.github.io/sfnetworks-webinar/slides -- and/or star this repo: https://github.com/sfnetworks/sfnetworks-webinar --- class: center, middle ## Hello from the team! .center[ ![:scale 20%](https://avatars1.githubusercontent.com/u/26540305?s=400&u=c576e87314499815cbf698b7781ee58fd1d773e2&v=4) ![:scale 20%](https://pbs.twimg.com/profile_images/1107610946623754240/BaNA8k1E_400x400.png) ![:scale 20%](https://avatars1.githubusercontent.com/u/22221146?s=400&u=3683a04d3f40823162d6c1ae5c51b6c9a5c0a9a5&v=4) ![:scale 20%](https://avatars2.githubusercontent.com/u/10034237?s=460&u=53193bed2fad4f0808b55a227f99897a8d63ebc2&v=4) ] -- .center[ what brought us together? ] --- class: center, middle ## Geospatial Networks -- .pull-left[ Road networks ![](figs/road_network.png) ] -- .pull-right[ River networks ![](figs/river_network.png) ] -- [**spnethack**](https://github.com/sfnetworks/spnethack) organised in Munster, 2019 Building on Luuk's MSc project while Robin was visiting [ifgi](https://www.uni-muenster.de/Geoinformatics/en/) Result: [Spatial networks in R with sf and tidygraph](https://www.r-spatial.org/r/2019/09/26/spatial-networks.html) blog post --- .pull-left-30[ ## Geospatial in R - [\#rspatial](https://twitter.com/search?q=%23rspatial) - `sf` - `stars` - `rgeos` - `rgdal` - `tmap` - `ggmap` - `mapview` - ... ] .pull-right-70[ <img src="slides_files/figure-html/geospatial_r-1.png" width="100%" /> ] --- .pull-left-30[ ## Networks in R - [statnet](http://statnet.org/) - `igraph` - `tidygraph` - `qgraph` - `ggraph` - `visNetwork` - `networkD3` - ... ] .pull-right-70[ <img src="slides_files/figure-html/network_ex-1.png" width="90%" /> ] --- class: center, middle # then... ## why a new package? --- .center[ ## why a new package? [![](figs/so_q1.png)](https://stackoverflow.com/questions/57833905/how-to-convert-a-list-of-sf-spatial-points-into-a-routable-graph) ] --- .center[ ## why a new package? [![:scale 80%](figs/gh_q1.png)](https://github.com/r-spatial/sf/issues/966) ] --- .center[ ## why a new package? [![](figs/gh_c1.png)](https://github.com/r-spatial/sf/issues/790#issuecomment-403831517) ] --- class: center ## why a new package? <center><blockquote class="twitter-tweet"><p lang="en" dir="ltr">One of the biggest reasons we still have ArcGIS licenses is for Network Analysis (drive times, service areas etc). Does anyone have <a href="https://twitter.com/hashtag/foss4g?src=hash&ref_src=twsrc%5Etfw">#foss4g</a> tools for this they like? Last time we tried pgRouting (yrs ago) it didn't feel fully formed yet, <a href="https://twitter.com/hashtag/gischat?src=hash&ref_src=twsrc%5Etfw">#gischat</a></p>— Zev Ross (@zevross) <a href="https://twitter.com/zevross/status/1089908839816794118?ref_src=twsrc%5Etfw">January 28, 2019</a></blockquote></center> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script> -- ... because open source can always get better! --- class: center, middle ## What is out there already? [dodgr](https://atfutures.github.io/dodgr/) [cppRouting](https://github.com/vlarmet/cppRouting) [shp2graph](https://r-forge.r-project.org/projects/shp2graph) [spnetwork](https://github.com/edzer/spnetwork) [stplanr](https://docs.ropensci.org/stplanr/) ... --- class: center, middle ## What do we propose? -- .pull-left[ ![](https://user-images.githubusercontent.com/520851/34887433-ce1d130e-f7c6-11e7-83fc-d60ad4fae6bd.gif) ] -- .pull-right[ ![:scale 38%](https://raw.githubusercontent.com/thomasp85/tidygraph/master/man/figures/logo.png) ] -- ## `sfnetworks` The best of both worlds! --- class: middle .pull-left-70[ .center[ ![:scale 80%](https://github.com/allisonhorst/stats-illustrations/raw/master/rstats-artwork/tidyverse_celestial.png) ] .footnote[ Artwork by [@allison_horst](https://twitter.com/allison_horst) ] ] .pull-right-30[ ### *tidy* workflows > In tidy data: 1. Each variable forms a column. 2. Each observation forms a row. 3. Each type of observational unit forms a table. .footnote[ Wickham, H. (2014). Tidy Data. Journal of Statistical Software, 59(10), 1 - 23. doi:http://dx.doi.org/10.18637/jss.v059.i10 ] - Supported by the *tidyverse* - Allows piping `%>%` structures ] --- class: center, middle .pull-left-70[ ![](https://github.com/allisonhorst/stats-illustrations/raw/master/rstats-artwork/sf.png) .footnote[ Artwork by [@allison_horst](https://twitter.com/allison_horst) ] ] .pull-right-30[ ### **`sf` package** Simple features for R Spatial vector data (points, lines and polygons) Compatible with *tidy* workflows S3 classes ] --- class: center, middle .pull-left-70[ ![:scale 80%](https://www.r-graph-gallery.com/339-circular-dendrogram-with-ggraph_files/figure-html/thecode8-1.png) .footnote[ Plot from [R GRaph Gallery](https://www.r-graph-gallery.com/339-circular-dendrogram-with-ggraph.html) ] ] .pull-right-30[ ### **`tidygraph` package** ![:scale 10%](https://avatars3.githubusercontent.com/u/3735184?s=200&v=4) Interfaces with [`igraph`](https://igraph.org/r/) ![:scale 8%](https://github.com/tidyverse/dplyr/raw/master/man/figures/logo.png) Supports [`dplyr`](https://dplyr.tidyverse.org/) *verbs* ![:scale 8%](https://raw.githubusercontent.com/thomasp85/tidygraph/master/man/figures/logo.png) Introduces new *verbs* specific to network data (e.g. `morph`, `bind_graphs`, `graph_join`) ![:scale 8%](https://github.com/thomasp85/ggraph/raw/master/man/figures/logo.png) Allows network visualization via [`ggraph`](https://ggraph.data-imaginist.com/) ] --- class: center, middle ## So, let's dive in... --- ### Installation Install the more stable master branch with: ```r remotes::install_github("luukvdmeer/sfnetworks") ``` Install the develop branch, where most of the development takes place and where PRs should be directed: ```r remotes::install_github("luukvdmeer/sfnetworks", ref = "develop") ``` --- ## `sfnetwork` data structure ### Philosophy -- > "... a close approximation of tidyness for relational data is two tidy data frames, one describing the node data and one describing the edge data." `tidygraph` introduction. -- <br> <br> > “A close approximation of tidyness for relational .orange[*geospatial data*] is two .orange[*sf objects*], one describing the node data and one describing the edge data.” `sfnetworks` adaption. --- ## `sfnetwork` data structure ### Construction - Nodes: `sf` object with `POINT` geometries - Edges: *to* and *from* column with end-points - Same CRS! --- class: split-40 count: false .left-panel-toyexample-user[ ```r *p1 = st_point(c(7, 51)) *p2 = st_point(c(7, 52)) *p3 = st_point(c(8, 52)) *st_sfc( * p1, p2, p3, * crs = 4326 * ) %>% st_sf() ``` ] .right-panel-toyexample-user[ ``` Simple feature collection with 3 features and 0 fields geometry type: POINT dimension: XY bbox: xmin: 7 ymin: 51 xmax: 8 ymax: 52 geographic CRS: WGS 84 geometry 1 POINT (7 51) 2 POINT (7 52) 3 POINT (8 52) ``` ] --- class: split-40 count: false .left-panel-toyexample-user[ ```r p1 = st_point(c(7, 51)) p2 = st_point(c(7, 52)) p3 = st_point(c(8, 52)) st_sfc( p1, p2, p3, crs = 4326 ) %>% st_sf() -> * nodes ``` ] .right-panel-toyexample-user[ ] --- class: split-40 count: false .left-panel-toyexample-user[ ```r p1 = st_point(c(7, 51)) p2 = st_point(c(7, 52)) p3 = st_point(c(8, 52)) st_sfc( p1, p2, p3, crs = 4326 ) %>% st_sf() -> nodes *st_sfc( * st_cast(st_union(p1,p2), "LINESTRING"), * st_cast(st_union(p1,p3), "LINESTRING"), * st_cast(st_union(p2,p3), "LINESTRING"), * crs = 4326 *) %>% st_sf() ``` ] .right-panel-toyexample-user[ ``` Simple feature collection with 3 features and 0 fields geometry type: LINESTRING dimension: XY bbox: xmin: 7 ymin: 51 xmax: 8 ymax: 52 geographic CRS: WGS 84 geometry 1 LINESTRING (7 51, 7 52) 2 LINESTRING (7 51, 8 52) 3 LINESTRING (7 52, 8 52) ``` ] --- class: split-40 count: false .left-panel-toyexample-user[ ```r p1 = st_point(c(7, 51)) p2 = st_point(c(7, 52)) p3 = st_point(c(8, 52)) st_sfc( p1, p2, p3, crs = 4326 ) %>% st_sf() -> nodes st_sfc( st_cast(st_union(p1,p2), "LINESTRING"), st_cast(st_union(p1,p3), "LINESTRING"), st_cast(st_union(p2,p3), "LINESTRING"), crs = 4326 ) %>% st_sf() -> * edges ``` ] .right-panel-toyexample-user[ ] --- class: split-40 count: false .left-panel-toyexample-user[ ```r p1 = st_point(c(7, 51)) p2 = st_point(c(7, 52)) p3 = st_point(c(8, 52)) st_sfc( p1, p2, p3, crs = 4326 ) %>% st_sf() -> nodes st_sfc( st_cast(st_union(p1,p2), "LINESTRING"), st_cast(st_union(p1,p3), "LINESTRING"), st_cast(st_union(p2,p3), "LINESTRING"), crs = 4326 ) %>% st_sf() -> edges *edges$from = c(1, 1, 2) *edges$to = c(2, 3, 3) ``` ] .right-panel-toyexample-user[ ] --- class: split-40 count: false .left-panel-toyexample-user[ ```r p1 = st_point(c(7, 51)) p2 = st_point(c(7, 52)) p3 = st_point(c(8, 52)) st_sfc( p1, p2, p3, crs = 4326 ) %>% st_sf() -> nodes st_sfc( st_cast(st_union(p1,p2), "LINESTRING"), st_cast(st_union(p1,p3), "LINESTRING"), st_cast(st_union(p2,p3), "LINESTRING"), crs = 4326 ) %>% st_sf() -> edges edges$from = c(1, 1, 2) edges$to = c(2, 3, 3) *sfnetwork(nodes, edges, directed = FALSE) ``` ] .right-panel-toyexample-user[ ``` Checking validity of network structure... Use force=TRUE to force construction without checks ``` <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>3</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>3</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:4326</span><span> </span><span style='color: #555555;'> # # An undirected simple graph with 1 component with spatially explicit edges # # Node Data: 3 x 1 (active)</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7 ymin: 51 xmax: 8 ymax: 52</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (7 51) </span><span style='color: #555555;'>2</span><span> (7 52) </span><span style='color: #555555;'>3</span><span> (8 52) </span><span style='color: #555555;'># # Edge Data: 3 x 3</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7 ymin: 51 xmax: 8 ymax: 52</span><span> from to geometry </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [°]></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 (7 51, 7 52) </span><span style='color: #555555;'>2</span><span> 1 3 (7 51, 8 52) </span><span style='color: #555555;'>3</span><span> 2 3 (7 52, 8 52) </span></CODE></PRE> ] <style> .left-panel-toyexample-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-toyexample-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-toyexample-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- ## `sfnetwork` data structure ### Foreign objects To convert foreign objects into an `sfnetwork` with `as_sfnetwork`, there are two conditions: - Object is or can be converted to a `tbl_graph` - At least the nodes can be converted to an `sf` object -- Or just an `sf` object with `POINT` or `LINESTRING` geometry --- class: split-40 count: false .left-panel-object1-user[ ```r *roxel ``` ] .right-panel-object1-user[ ``` Simple feature collection with 851 features and 2 fields geometry type: LINESTRING dimension: XY bbox: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612 geographic CRS: WGS 84 # A tibble: 851 x 3 name type geometry <fct> <fct> <LINESTRING [°]> 1 Havixbecker ~ residen~ (7.533722 51.95556, 7.533461 51.95576) 2 Pienersallee seconda~ (7.532442 51.95422, 7.53236 51.95377, 7.532~ 3 Schulte-Bern~ residen~ (7.532709 51.95209, 7.532823 51.95239, 7.53~ 4 <NA> path (7.540063 51.94468, 7.539696 51.94479, 7.53~ 5 Welsingheide residen~ (7.537673 51.9475, 7.537614 51.94562) 6 <NA> footway (7.543791 51.94733, 7.54369 51.94686, 7.543~ 7 <NA> footway (7.54012 51.94478, 7.539931 51.94514) 8 <NA> path (7.53822 51.94546, 7.538131 51.94549, 7.538~ 9 <NA> track (7.540063 51.94468, 7.540338 51.94468, 7.54~ 10 <NA> track (7.5424 51.94599, 7.54205 51.94629, 7.54196~ # ... with 841 more rows ``` ] --- class: split-40 count: false .left-panel-object1-user[ ```r roxel %>% * as_sfnetwork() ``` ] .right-panel-object1-user[ ``` # An sfnetwork with 701 nodes and 851 edges # # CRS: EPSG:4326 # # A directed multigraph with 14 components with spatially explicit edges # # Node Data: 701 x 1 (active) # Geometry type: POINT # Dimension: XY # Bounding box: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612 geometry <POINT [°]> 1 (7.533722 51.95556) 2 (7.533461 51.95576) 3 (7.532442 51.95422) 4 (7.53209 51.95328) 5 (7.532709 51.95209) 6 (7.532869 51.95257) # ... with 695 more rows # # Edge Data: 851 x 5 # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612 from to name type geometry <int> <int> <fct> <fct> <LINESTRING [°]> 1 1 2 Havixbecke~ reside~ (7.533722 51.95556, 7.533461 51.955~ 2 3 4 Pienersall~ second~ (7.532442 51.95422, 7.53236 51.9537~ 3 5 6 Schulte-Be~ reside~ (7.532709 51.95209, 7.532823 51.952~ # ... with 848 more rows ``` ] --- class: split-40 count: false .left-panel-object1-user[ ```r roxel %>% as_sfnetwork() -> * net ``` ] .right-panel-object1-user[ ] <style> .left-panel-object1-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-object1-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-object1-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-object2-user[ ```r *net %>% * st_crs() ``` ] .right-panel-object2-user[ ``` Coordinate Reference System: User input: EPSG:4326 wkt: GEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], CS[ellipsoidal,2], AXIS["geodetic latitude (Lat)",north, ORDER[1], ANGLEUNIT["degree",0.0174532925199433]], AXIS["geodetic longitude (Lon)",east, ORDER[2], ANGLEUNIT["degree",0.0174532925199433]], USAGE[ SCOPE["unknown"], AREA["World"], BBOX[-90,-180,90,180]], ID["EPSG",4326]] ``` ] --- class: split-40 count: false .left-panel-object2-user[ ```r net %>% st_crs() *net %>% * st_transform(3035) ``` ] .right-panel-object2-user[ ``` Coordinate Reference System: User input: EPSG:4326 wkt: GEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], CS[ellipsoidal,2], AXIS["geodetic latitude (Lat)",north, ORDER[1], ANGLEUNIT["degree",0.0174532925199433]], AXIS["geodetic longitude (Lon)",east, ORDER[2], ANGLEUNIT["degree",0.0174532925199433]], USAGE[ SCOPE["unknown"], AREA["World"], BBOX[-90,-180,90,180]], ID["EPSG",4326]] ``` ``` # An sfnetwork with 701 nodes and 851 edges # # CRS: EPSG:3035 # # A directed multigraph with 14 components with spatially explicit edges # # Node Data: 701 x 1 (active) # Geometry type: POINT # Dimension: XY # Bounding box: xmin: 4150707 ymin: 3206375 xmax: 4152367 ymax: # 3208565 geometry <POINT [m]> 1 (4151491 3207923) 2 (4151474 3207946) 3 (4151398 3207777) 4 (4151370 3207673) 5 (4151408 3207539) 6 (4151421 3207592) # ... with 695 more rows # # Edge Data: 851 x 5 # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: 4150707 ymin: 3206375 xmax: 4152367 ymax: # 3208565 from to name type geometry <int> <int> <fct> <fct> <LINESTRING [m]> 1 1 2 Havixbecker~ reside~ (4151491 3207923, 4151474 3207946) 2 3 4 Pienersallee second~ (4151398 3207777, 4151390 3207727,~ 3 5 6 Schulte-Ber~ reside~ (4151408 3207539, 4151417 3207573,~ # ... with 848 more rows ``` ] <style> .left-panel-object2-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-object2-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-object2-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-object4-user[ ```r *net %>% * sf_attr("sf_column", "nodes") ``` ] .right-panel-object4-user[ ``` [1] "geometry" ``` ] --- class: split-40 count: false .left-panel-object4-user[ ```r net %>% sf_attr("sf_column", "nodes") *net %>% * sf_attr("agr", "edges") # BREAK ``` ] .right-panel-object4-user[ ``` [1] "geometry" ``` ``` from to name type <NA> <NA> <NA> <NA> Levels: constant aggregate identity ``` ] <style> .left-panel-object4-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-object4-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-object4-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-object5-user[ ```r *par(mar = c(1, 1, 1, 1), bg = NA) *plot(net) ``` ] .right-panel-object5-user[ <img src="slides_files/figure-html/object5_user_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-panel-object5-user[ ```r par(mar = c(1, 1, 1, 1), bg = NA) plot(net) *net %>% * class() ``` ] .right-panel-object5-user[ <img src="slides_files/figure-html/object5_user_2_output-1.png" width="432" /> ``` [1] "sfnetwork" "tbl_graph" "igraph" ``` ] <style> .left-panel-object5-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-object5-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-object5-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- .pull-left-30[ ## Graph operations `sfnetwork` objects subclass `tbl_graph` objects, so any `igraph` algorithm and tidy wrappers from `tidygraph` are supported. Check out the possibilities on the [tidygraph introduction](https://www.data-imaginist.com/2017/introducing-tidygraph/). ] .pull-right-70[ <img src="slides_files/figure-html/unnamed-chunk-4-1.png" width="100%" /> ] --- class: split-40 count: false .left-panel-sfnetworks_options-non_seq[ ```r roxel %>% as_sfnetwork( ) ``` ] .right-panel-sfnetworks_options-non_seq[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>701</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>851</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:4326</span><span> </span><span style='color: #555555;'> # # A directed multigraph with 14 components with spatially explicit edges # # Node Data: 701 x 1 (active)</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (7.533722 51.95556) </span><span style='color: #555555;'>2</span><span> (7.533461 51.95576) </span><span style='color: #555555;'>3</span><span> (7.532442 51.95422) </span><span style='color: #555555;'>4</span><span> (7.53209 51.95328) </span><span style='color: #555555;'>5</span><span> (7.532709 51.95209) </span><span style='color: #555555;'>6</span><span> (7.532869 51.95257) </span><span style='color: #555555;'># ... with 695 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 851 x 5</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> from to name type geometry </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [°]></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havixbecke~ reside~ (7.533722 51.95556, 7.533461 51.955~ </span><span style='color: #555555;'>2</span><span> 3 4 Pienersall~ second~ (7.532442 51.95422, 7.53236 51.9537~ </span><span style='color: #555555;'>3</span><span> 5 6 Schulte-Be~ reside~ (7.532709 51.95209, 7.532823 51.952~ </span><span style='color: #555555;'># ... with 848 more rows</span><span> </span></CODE></PRE> ] --- class: split-40 count: false .left-panel-sfnetworks_options-non_seq[ ```r roxel %>% as_sfnetwork( * directed = F, ) ``` ] .right-panel-sfnetworks_options-non_seq[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>701</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>851</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:4326</span><span> </span><span style='color: #555555;'> # # An undirected multigraph with 14 components with spatially explicit edges # # Node Data: 701 x 1 (active)</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (7.533722 51.95556) </span><span style='color: #555555;'>2</span><span> (7.533461 51.95576) </span><span style='color: #555555;'>3</span><span> (7.532442 51.95422) </span><span style='color: #555555;'>4</span><span> (7.53209 51.95328) </span><span style='color: #555555;'>5</span><span> (7.532709 51.95209) </span><span style='color: #555555;'>6</span><span> (7.532869 51.95257) </span><span style='color: #555555;'># ... with 695 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 851 x 5</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> from to name type geometry </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [°]></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havixbecke~ reside~ (7.533722 51.95556, 7.533461 51.955~ </span><span style='color: #555555;'>2</span><span> 3 4 Pienersall~ second~ (7.532442 51.95422, 7.53236 51.9537~ </span><span style='color: #555555;'>3</span><span> 5 6 Schulte-Be~ reside~ (7.532709 51.95209, 7.532823 51.952~ </span><span style='color: #555555;'># ... with 848 more rows</span><span> </span></CODE></PRE> ] --- class: split-40 count: false .left-panel-sfnetworks_options-non_seq[ ```r roxel %>% as_sfnetwork( directed = F, * edges_as_lines = F ) ``` ] .right-panel-sfnetworks_options-non_seq[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>701</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>851</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:4326</span><span> </span><span style='color: #555555;'> # # An undirected multigraph with 14 components with spatially implicit edges # # Node Data: 701 x 1 (active)</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (7.533722 51.95556) </span><span style='color: #555555;'>2</span><span> (7.533461 51.95576) </span><span style='color: #555555;'>3</span><span> (7.532442 51.95422) </span><span style='color: #555555;'>4</span><span> (7.53209 51.95328) </span><span style='color: #555555;'>5</span><span> (7.532709 51.95209) </span><span style='color: #555555;'>6</span><span> (7.532869 51.95257) </span><span style='color: #555555;'># ... with 695 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 851 x 4</span><span> from to name type </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havixbecker Strasse residential </span><span style='color: #555555;'>2</span><span> 3 4 Pienersallee secondary </span><span style='color: #555555;'>3</span><span> 5 6 Schulte-Bernd-Strasse residential </span><span style='color: #555555;'># ... with 848 more rows</span><span> </span></CODE></PRE> ] <style> .left-panel-sfnetworks_options-non_seq { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-sfnetworks_options-non_seq { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-sfnetworks_options-non_seq { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> .note[See issue [#50](https://github.com/luukvdmeer/sfnetworks/issues/50)] --- class: split-40 count: false .left-panel-activate-user[ ```r *net ``` ] .right-panel-activate-user[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>701</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>851</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:4326</span><span> </span><span style='color: #555555;'> # # A directed multigraph with 14 components with spatially explicit edges # # Node Data: 701 x 1 (active)</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (7.533722 51.95556) </span><span style='color: #555555;'>2</span><span> (7.533461 51.95576) </span><span style='color: #555555;'>3</span><span> (7.532442 51.95422) </span><span style='color: #555555;'>4</span><span> (7.53209 51.95328) </span><span style='color: #555555;'>5</span><span> (7.532709 51.95209) </span><span style='color: #555555;'>6</span><span> (7.532869 51.95257) </span><span style='color: #555555;'># ... with 695 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 851 x 5</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> from to name type geometry </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [°]></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havixbecke~ reside~ (7.533722 51.95556, 7.533461 51.955~ </span><span style='color: #555555;'>2</span><span> 3 4 Pienersall~ second~ (7.532442 51.95422, 7.53236 51.9537~ </span><span style='color: #555555;'>3</span><span> 5 6 Schulte-Be~ reside~ (7.532709 51.95209, 7.532823 51.952~ </span><span style='color: #555555;'># ... with 848 more rows</span><span> </span></CODE></PRE> ] --- class: split-40 count: false .left-panel-activate-user[ ```r net %>% * activate("edges") ``` ] .right-panel-activate-user[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>701</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>851</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:4326</span><span> </span><span style='color: #555555;'> # # A directed multigraph with 14 components with spatially explicit edges # # Edge Data: 851 x 5 (active)</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> from to name type geometry </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [°]></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havixbeck~ reside~ (7.533722 51.95556, 7.533461 51.9557~ </span><span style='color: #555555;'>2</span><span> 3 4 Pienersal~ second~ (7.532442 51.95422, 7.53236 51.95377~ </span><span style='color: #555555;'>3</span><span> 5 6 Schulte-B~ reside~ (7.532709 51.95209, 7.532823 51.9523~ </span><span style='color: #555555;'>4</span><span> 7 8 </span><span style='color: #BB0000;'>NA</span><span> path (7.540063 51.94468, 7.539696 51.9447~ </span><span style='color: #555555;'>5</span><span> 9 10 Welsinghe~ reside~ (7.537673 51.9475, 7.537614 51.94562) </span><span style='color: #555555;'>6</span><span> 11 12 </span><span style='color: #BB0000;'>NA</span><span> footway (7.543791 51.94733, 7.54369 51.94686~ </span><span style='color: #555555;'># ... with 845 more rows</span><span> </span><span style='color: #555555;'># # Node Data: 701 x 1</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (7.533722 51.95556) </span><span style='color: #555555;'>2</span><span> (7.533461 51.95576) </span><span style='color: #555555;'>3</span><span> (7.532442 51.95422) </span><span style='color: #555555;'># ... with 698 more rows</span><span> </span></CODE></PRE> ] --- class: split-40 count: false .left-panel-activate-user[ ```r net %>% activate("edges") %>% * st_geometry() ``` ] .right-panel-activate-user[ ``` Geometry set for 851 features geometry type: LINESTRING dimension: XY bbox: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612 geographic CRS: WGS 84 First 5 geometries: ``` ``` LINESTRING (7.533722 51.95556, 7.533461 51.95576) ``` ``` LINESTRING (7.532442 51.95422, 7.53236 51.95377... ``` ``` LINESTRING (7.532709 51.95209, 7.532823 51.9523... ``` ``` LINESTRING (7.540063 51.94468, 7.539696 51.9447... ``` ``` LINESTRING (7.537673 51.9475, 7.537614 51.94562) ``` ] --- class: split-40 count: false .left-panel-activate-user[ ```r net %>% activate("edges") %>% st_geometry() *net %>% * activate("nodes") %>% * st_geometry() ``` ] .right-panel-activate-user[ ``` Geometry set for 851 features geometry type: LINESTRING dimension: XY bbox: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612 geographic CRS: WGS 84 First 5 geometries: ``` ``` LINESTRING (7.533722 51.95556, 7.533461 51.95576) ``` ``` LINESTRING (7.532442 51.95422, 7.53236 51.95377... ``` ``` LINESTRING (7.532709 51.95209, 7.532823 51.9523... ``` ``` LINESTRING (7.540063 51.94468, 7.539696 51.9447... ``` ``` LINESTRING (7.537673 51.9475, 7.537614 51.94562) ``` ``` Geometry set for 701 features geometry type: POINT dimension: XY bbox: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612 geographic CRS: WGS 84 First 5 geometries: ``` ``` POINT (7.533722 51.95556) ``` ``` POINT (7.533461 51.95576) ``` ``` POINT (7.532442 51.95422) ``` ``` POINT (7.53209 51.95328) ``` ``` POINT (7.532709 51.95209) ``` ] <style> .left-panel-activate-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-activate-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-activate-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-filter-user[ ```r *net = roxel %>% as_sfnetwork(directed = F) ``` ] .right-panel-filter-user[ ] --- class: split-40 count: false .left-panel-filter-user[ ```r net = roxel %>% as_sfnetwork(directed = F) *par(mar = c(1, 1, 1, 1), bg = NA) *plot(net) ``` ] .right-panel-filter-user[ <img src="slides_files/figure-html/filter_user_2_output-1.png" width="432" /> ] --- class: split-40 count: false .left-panel-filter-user[ ```r net = roxel %>% as_sfnetwork(directed = F) par(mar = c(1, 1, 1, 1), bg = NA) plot(net) *rect = st_multipoint(c( * st_point(c(7.53173, 51.95662)), * st_point(c(7.53173, 51.95190)), * st_point(c(7.53778, 51.95190)), * st_point(c(7.53778, 51.95662)) * )) %>% * st_cast('POLYGON') %>% * st_sfc(crs = 4326) *rect %>% * plot( * border = "Red", * lwd = 2, * add = TRUE *) ``` ] .right-panel-filter-user[ <img src="slides_files/figure-html/filter_user_3_output-1.png" width="432" /> ] --- class: split-40 count: false .left-panel-filter-user[ ```r net = roxel %>% as_sfnetwork(directed = F) par(mar = c(1, 1, 1, 1), bg = NA) plot(net) rect = st_multipoint(c( st_point(c(7.53173, 51.95662)), st_point(c(7.53173, 51.95190)), st_point(c(7.53778, 51.95190)), st_point(c(7.53778, 51.95662)) )) %>% st_cast('POLYGON') %>% st_sfc(crs = 4326) rect %>% plot( border = "Red", lwd = 2, add = TRUE ) *net %>% * st_filter(rect, .pred = st_intersects) %>% * plot(col = "Orange", add = TRUE) ``` ] .right-panel-filter-user[ ``` although coordinates are longitude/latitude, st_intersects assumes that they are planar although coordinates are longitude/latitude, st_intersects assumes that they are planar ``` <img src="slides_files/figure-html/filter_user_4_output-1.png" width="432" /> ] <style> .left-panel-filter-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-filter-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-filter-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> .note[Other supported `sf` functions: spatial joins, coordinate transformations] --- ### Not supported functions > There is a clear limitation in the relational data structure that requires rows to maintain their identity. > For sfnetwork objects, this also means that the geometries of features should be maintained, or at least the endpoints of these geometries, in the case of the edges. > That is, functions that summarise geometries, or (may) change their .orange[type, shape or position], are not supported. --- class: split-40 count: false .left-panel-extraction-user[ ```r *net %>% * st_transform(3035) %>% * activate("nodes") ``` ] .right-panel-extraction-user[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>701</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>851</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:3035</span><span> </span><span style='color: #555555;'> # # An undirected multigraph with 14 components with spatially explicit edges # # Node Data: 701 x 1 (active)</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 4150707 ymin: 3206375 xmax: 4152367 ymax: # 3208565</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [m]></span><span> </span><span style='color: #555555;'>1</span><span> (4151491 3207923) </span><span style='color: #555555;'>2</span><span> (4151474 3207946) </span><span style='color: #555555;'>3</span><span> (4151398 3207777) </span><span style='color: #555555;'>4</span><span> (4151370 3207673) </span><span style='color: #555555;'>5</span><span> (4151408 3207539) </span><span style='color: #555555;'>6</span><span> (4151421 3207592) </span><span style='color: #555555;'># ... with 695 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 851 x 5</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 4150707 ymin: 3206375 xmax: 4152367 ymax: # 3208565</span><span> from to name type geometry </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [m]></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havixbecker~ reside~ (4151491 3207923, 4151474 3207946) </span><span style='color: #555555;'>2</span><span> 3 4 Pienersallee second~ (4151398 3207777, 4151390 3207727,~ </span><span style='color: #555555;'>3</span><span> 5 6 Schulte-Ber~ reside~ (4151408 3207539, 4151417 3207573,~ </span><span style='color: #555555;'># ... with 848 more rows</span><span> </span></CODE></PRE> ] --- class: split-40 count: false .left-panel-extraction-user[ ```r net %>% st_transform(3035) %>% activate("nodes") %>% * st_as_sf() ``` ] .right-panel-extraction-user[ <PRE class="fansi fansi-output"><CODE>Simple feature collection with 701 features and 0 fields geometry type: POINT dimension: XY bbox: xmin: 4150707 ymin: 3206375 xmax: 4152367 ymax: 3208565 projected CRS: ETRS89-extended / LAEA Europe <span style='color: #555555;'># A tibble: 701 x 1</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [m]></span><span> </span><span style='color: #555555;'> 1</span><span> (4151491 3207923) </span><span style='color: #555555;'> 2</span><span> (4151474 3207946) </span><span style='color: #555555;'> 3</span><span> (4151398 3207777) </span><span style='color: #555555;'> 4</span><span> (4151370 3207673) </span><span style='color: #555555;'> 5</span><span> (4151408 3207539) </span><span style='color: #555555;'> 6</span><span> (4151421 3207592) </span><span style='color: #555555;'> 7</span><span> (4151885 3206698) </span><span style='color: #555555;'> 8</span><span> (4151762 3206789) </span><span style='color: #555555;'> 9</span><span> (4151732 3207017) </span><span style='color: #555555;'>10</span><span> (4151721 3206809) </span><span style='color: #555555;'># ... with 691 more rows</span><span> </span></CODE></PRE> ] --- class: split-40 count: false .left-panel-extraction-user[ ```r net %>% st_transform(3035) %>% activate("nodes") %>% st_as_sf() %>% * mutate( * aoi = st_area( * st_collection_extract( * st_voronoi(do.call(c, st_geometry(.))) * ))) ``` ] .right-panel-extraction-user[ <PRE class="fansi fansi-output"><CODE>Simple feature collection with 701 features and 1 field geometry type: POINT dimension: XY bbox: xmin: 4150707 ymin: 3206375 xmax: 4152367 ymax: 3208565 projected CRS: ETRS89-extended / LAEA Europe <span style='color: #555555;'># A tibble: 701 x 2</span><span> geometry aoi </span><span style='color: #555555;'>*</span><span> </span><span style='color: #555555;font-style: italic;'><POINT [m]></span><span> </span><span style='color: #555555;font-style: italic;'><dbl></span><span> </span><span style='color: #555555;'> 1</span><span> (4151491 3207923) 1</span><span style='text-decoration: underline;'>837</span><span>540. </span><span style='color: #555555;'> 2</span><span> (4151474 3207946) 2</span><span style='text-decoration: underline;'>563</span><span>698. </span><span style='color: #555555;'> 3</span><span> (4151398 3207777) </span><span style='text-decoration: underline;'>36</span><span>462. </span><span style='color: #555555;'> 4</span><span> (4151370 3207673) </span><span style='text-decoration: underline;'>359</span><span>624. </span><span style='color: #555555;'> 5</span><span> (4151408 3207539) </span><span style='text-decoration: underline;'>12</span><span>954. </span><span style='color: #555555;'> 6</span><span> (4151421 3207592) </span><span style='text-decoration: underline;'>11</span><span>089. </span><span style='color: #555555;'> 7</span><span> (4151885 3206698) </span><span style='text-decoration: underline;'>190</span><span>473. </span><span style='color: #555555;'> 8</span><span> (4151762 3206789) </span><span style='text-decoration: underline;'>26</span><span>370. </span><span style='color: #555555;'> 9</span><span> (4151732 3207017) </span><span style='text-decoration: underline;'>8</span><span>416. </span><span style='color: #555555;'>10</span><span> (4151721 3206809) </span><span style='text-decoration: underline;'>4</span><span>867. </span><span style='color: #555555;'># ... with 691 more rows</span><span> </span></CODE></PRE> ] --- class: split-40 count: false .left-panel-extraction-user[ ```r net %>% st_transform(3035) %>% activate("nodes") %>% st_as_sf() %>% mutate( aoi = st_area( st_collection_extract( st_voronoi(do.call(c, st_geometry(.))) ))) -> * y *net %>% * st_transform(3035) %>% * activate("nodes") ``` ] .right-panel-extraction-user[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>701</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>851</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:3035</span><span> </span><span style='color: #555555;'> # # An undirected multigraph with 14 components with spatially explicit edges # # Node Data: 701 x 1 (active)</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 4150707 ymin: 3206375 xmax: 4152367 ymax: # 3208565</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [m]></span><span> </span><span style='color: #555555;'>1</span><span> (4151491 3207923) </span><span style='color: #555555;'>2</span><span> (4151474 3207946) </span><span style='color: #555555;'>3</span><span> (4151398 3207777) </span><span style='color: #555555;'>4</span><span> (4151370 3207673) </span><span style='color: #555555;'>5</span><span> (4151408 3207539) </span><span style='color: #555555;'>6</span><span> (4151421 3207592) </span><span style='color: #555555;'># ... with 695 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 851 x 5</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 4150707 ymin: 3206375 xmax: 4152367 ymax: # 3208565</span><span> from to name type geometry </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [m]></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havixbecker~ reside~ (4151491 3207923, 4151474 3207946) </span><span style='color: #555555;'>2</span><span> 3 4 Pienersallee second~ (4151398 3207777, 4151390 3207727,~ </span><span style='color: #555555;'>3</span><span> 5 6 Schulte-Ber~ reside~ (4151408 3207539, 4151417 3207573,~ </span><span style='color: #555555;'># ... with 848 more rows</span><span> </span></CODE></PRE> ] --- class: split-40 count: false .left-panel-extraction-user[ ```r net %>% st_transform(3035) %>% activate("nodes") %>% st_as_sf() %>% mutate( aoi = st_area( st_collection_extract( st_voronoi(do.call(c, st_geometry(.))) ))) -> y net %>% st_transform(3035) %>% activate("nodes") %>% * st_join(y) ``` ] .right-panel-extraction-user[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>701</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>851</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:3035</span><span> </span><span style='color: #555555;'> # # An undirected multigraph with 14 components with spatially explicit edges # # Node Data: 701 x 2 (active)</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 4150707 ymin: 3206375 xmax: 4152367 ymax: # 3208565</span><span> geometry aoi </span><span style='color: #555555;font-style: italic;'><POINT [m]></span><span> </span><span style='color: #555555;font-style: italic;'><dbl></span><span> </span><span style='color: #555555;'>1</span><span> (4151491 3207923) 1</span><span style='text-decoration: underline;'>837</span><span>540. </span><span style='color: #555555;'>2</span><span> (4151474 3207946) 2</span><span style='text-decoration: underline;'>563</span><span>698. </span><span style='color: #555555;'>3</span><span> (4151398 3207777) </span><span style='text-decoration: underline;'>36</span><span>462. </span><span style='color: #555555;'>4</span><span> (4151370 3207673) </span><span style='text-decoration: underline;'>359</span><span>624. </span><span style='color: #555555;'>5</span><span> (4151408 3207539) </span><span style='text-decoration: underline;'>12</span><span>954. </span><span style='color: #555555;'>6</span><span> (4151421 3207592) </span><span style='text-decoration: underline;'>11</span><span>089. </span><span style='color: #555555;'># ... with 695 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 851 x 5</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 4150707 ymin: 3206375 xmax: 4152367 ymax: # 3208565</span><span> from to name type geometry </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [m]></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havixbecker~ reside~ (4151491 3207923, 4151474 3207946) </span><span style='color: #555555;'>2</span><span> 3 4 Pienersallee second~ (4151398 3207777, 4151390 3207727,~ </span><span style='color: #555555;'>3</span><span> 5 6 Schulte-Ber~ reside~ (4151408 3207539, 4151417 3207573,~ </span><span style='color: #555555;'># ... with 848 more rows</span><span> </span></CODE></PRE> ] <style> .left-panel-extraction-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-extraction-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-extraction-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: center, middle ## Extending the vocabulary --- class: split-40 count: false .left-panel-edgemeasures-rotate[ ```r net %>% activate("edges") %>% mutate(length = edge_length()) ``` ] .right-panel-edgemeasures-rotate[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>701</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>851</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:4326</span><span> </span><span style='color: #555555;'> # # An undirected multigraph with 14 components with spatially explicit edges # # Edge Data: 851 x 6 (active)</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> from to name type geometry length </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [°]></span><span> </span><span style='color: #555555;'>[m]</span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havixbe~ resid~ (7.533722 51.95556, 7.533461 5~ 28.859~ </span><span style='color: #555555;'>2</span><span> 3 4 Pieners~ secon~ (7.532442 51.95422, 7.53236 51~ 107.704~ </span><span style='color: #555555;'>3</span><span> 5 6 Schulte~ resid~ (7.532709 51.95209, 7.532823 5~ 54.362~ </span><span style='color: #555555;'>4</span><span> 7 8 </span><span style='color: #BB0000;'>NA</span><span> path (7.540063 51.94468, 7.539696 5~ 155.230~ </span><span style='color: #555555;'>5</span><span> 9 10 Welsing~ resid~ (7.537673 51.9475, 7.537614 51~ 208.663~ </span><span style='color: #555555;'>6</span><span> 11 12 </span><span style='color: #BB0000;'>NA</span><span> footw~ (7.543791 51.94733, 7.54369 51~ 63.023~ </span><span style='color: #555555;'># ... with 845 more rows</span><span> </span><span style='color: #555555;'># # Node Data: 701 x 1</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (7.533722 51.95556) </span><span style='color: #555555;'>2</span><span> (7.533461 51.95576) </span><span style='color: #555555;'>3</span><span> (7.532442 51.95422) </span><span style='color: #555555;'># ... with 698 more rows</span><span> </span></CODE></PRE> ] --- class: split-40 count: false .left-panel-edgemeasures-rotate[ ```r net %>% activate("edges") %>% * mutate(straight = edge_straight_length()) ``` ] .right-panel-edgemeasures-rotate[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>701</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>851</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:4326</span><span> </span><span style='color: #555555;'> # # An undirected multigraph with 14 components with spatially explicit edges # # Edge Data: 851 x 6 (active)</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> from to name type geometry straight </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [°]></span><span> </span><span style='color: #555555;'>[m]</span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havixbe~ resid~ (7.533722 51.95556, 7.533461 5~ 28.859~ </span><span style='color: #555555;'>2</span><span> 3 4 Pieners~ secon~ (7.532442 51.95422, 7.53236 51~ 107.073~ </span><span style='color: #555555;'>3</span><span> 5 6 Schulte~ resid~ (7.532709 51.95209, 7.532823 5~ 54.336~ </span><span style='color: #555555;'>4</span><span> 7 8 </span><span style='color: #BB0000;'>NA</span><span> path (7.540063 51.94468, 7.539696 5~ 153.916~ </span><span style='color: #555555;'>5</span><span> 9 10 Welsing~ resid~ (7.537673 51.9475, 7.537614 51~ 208.663~ </span><span style='color: #555555;'>6</span><span> 11 12 </span><span style='color: #BB0000;'>NA</span><span> footw~ (7.543791 51.94733, 7.54369 51~ 61.702~ </span><span style='color: #555555;'># ... with 845 more rows</span><span> </span><span style='color: #555555;'># # Node Data: 701 x 1</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (7.533722 51.95556) </span><span style='color: #555555;'>2</span><span> (7.533461 51.95576) </span><span style='color: #555555;'>3</span><span> (7.532442 51.95422) </span><span style='color: #555555;'># ... with 698 more rows</span><span> </span></CODE></PRE> ] --- class: split-40 count: false .left-panel-edgemeasures-rotate[ ```r net %>% activate("edges") %>% * mutate(circuity = edge_circuity()) ``` ] .right-panel-edgemeasures-rotate[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>701</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>851</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:4326</span><span> </span><span style='color: #555555;'> # # An undirected multigraph with 14 components with spatially explicit edges # # Edge Data: 851 x 6 (active)</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> from to name type geometry circuity </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [°]></span><span> </span><span style='color: #555555;'>[1]</span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havixbe~ resid~ (7.533722 51.95556, 7.533461 5~ 1.000000 </span><span style='color: #555555;'>2</span><span> 3 4 Pieners~ secon~ (7.532442 51.95422, 7.53236 51~ 1.005896 </span><span style='color: #555555;'>3</span><span> 5 6 Schulte~ resid~ (7.532709 51.95209, 7.532823 5~ 1.000472 </span><span style='color: #555555;'>4</span><span> 7 8 </span><span style='color: #BB0000;'>NA</span><span> path (7.540063 51.94468, 7.539696 5~ 1.008539 </span><span style='color: #555555;'>5</span><span> 9 10 Welsing~ resid~ (7.537673 51.9475, 7.537614 51~ 1.000000 </span><span style='color: #555555;'>6</span><span> 11 12 </span><span style='color: #BB0000;'>NA</span><span> footw~ (7.543791 51.94733, 7.54369 51~ 1.021405 </span><span style='color: #555555;'># ... with 845 more rows</span><span> </span><span style='color: #555555;'># # Node Data: 701 x 1</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (7.533722 51.95556) </span><span style='color: #555555;'>2</span><span> (7.533461 51.95576) </span><span style='color: #555555;'>3</span><span> (7.532442 51.95422) </span><span style='color: #555555;'># ... with 698 more rows</span><span> </span></CODE></PRE> ] <style> .left-panel-edgemeasures-rotate { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-edgemeasures-rotate { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-edgemeasures-rotate { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-shortestpath-user[ ```r *net_proj = net %>% st_transform(3035) *p1 = net_proj %>% * activate(nodes) %>% * st_as_sf() %>% * slice(1) *p2 = net_proj %>% * activate(nodes) %>% * st_as_sf() %>% * slice(9) ``` ] .right-panel-shortestpath-user[ ] --- class: split-40 count: false .left-panel-shortestpath-user[ ```r net_proj = net %>% st_transform(3035) p1 = net_proj %>% activate(nodes) %>% st_as_sf() %>% slice(1) p2 = net_proj %>% activate(nodes) %>% st_as_sf() %>% slice(9) *p3 = sf::st_sfc( * sf::st_geometry(p1)[[1]] + sf::st_point(c(500, 500)), * crs = sf::st_crs(p1) *) *p4 = sf::st_sfc( * sf::st_geometry(p2)[[1]] + sf::st_point(c(-500, -500)), * crs = sf::st_crs(p2) *) ``` ] .right-panel-shortestpath-user[ ] --- class: split-40 count: false .left-panel-shortestpath-user[ ```r net_proj = net %>% st_transform(3035) p1 = net_proj %>% activate(nodes) %>% st_as_sf() %>% slice(1) p2 = net_proj %>% activate(nodes) %>% st_as_sf() %>% slice(9) p3 = sf::st_sfc( sf::st_geometry(p1)[[1]] + sf::st_point(c(500, 500)), crs = sf::st_crs(p1) ) p4 = sf::st_sfc( sf::st_geometry(p2)[[1]] + sf::st_point(c(-500, -500)), crs = sf::st_crs(p2) ) *par(mar = c(1,1,1,1), bg = NA) *plot(net_proj) ``` ] .right-panel-shortestpath-user[ <img src="slides_files/figure-html/shortestpath_user_3_output-1.png" width="432" /> ] --- class: split-40 count: false .left-panel-shortestpath-user[ ```r net_proj = net %>% st_transform(3035) p1 = net_proj %>% activate(nodes) %>% st_as_sf() %>% slice(1) p2 = net_proj %>% activate(nodes) %>% st_as_sf() %>% slice(9) p3 = sf::st_sfc( sf::st_geometry(p1)[[1]] + sf::st_point(c(500, 500)), crs = sf::st_crs(p1) ) p4 = sf::st_sfc( sf::st_geometry(p2)[[1]] + sf::st_point(c(-500, -500)), crs = sf::st_crs(p2) ) par(mar = c(1,1,1,1), bg = NA) plot(net_proj) *plot(p3, col = "red", pch = 20, cex = 2, add = TRUE) ``` ] .right-panel-shortestpath-user[ <img src="slides_files/figure-html/shortestpath_user_4_output-1.png" width="432" /> ] --- class: split-40 count: false .left-panel-shortestpath-user[ ```r net_proj = net %>% st_transform(3035) p1 = net_proj %>% activate(nodes) %>% st_as_sf() %>% slice(1) p2 = net_proj %>% activate(nodes) %>% st_as_sf() %>% slice(9) p3 = sf::st_sfc( sf::st_geometry(p1)[[1]] + sf::st_point(c(500, 500)), crs = sf::st_crs(p1) ) p4 = sf::st_sfc( sf::st_geometry(p2)[[1]] + sf::st_point(c(-500, -500)), crs = sf::st_crs(p2) ) par(mar = c(1,1,1,1), bg = NA) plot(net_proj) plot(p3, col = "red", pch = 20, cex = 2, add = TRUE) *plot(p4, col = "red", pch = 20, cex = 2, add = TRUE) ``` ] .right-panel-shortestpath-user[ <img src="slides_files/figure-html/shortestpath_user_5_output-1.png" width="432" /> ] <style> .left-panel-shortestpath-user { color: #777; width: 50%; height: 92%; float: left; font-size: 80% } .right-panel-shortestpath-user { width: 45%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-shortestpath-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-shortestpath1-user[ ```r *net_proj %>% * activate("edges") %>% * mutate(weight = edge_length()) ``` ] .right-panel-shortestpath1-user[ ``` # An sfnetwork with 701 nodes and 851 edges # # CRS: EPSG:3035 # # An undirected multigraph with 14 components with spatially explicit edges # # Edge Data: 851 x 6 (active) # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: 4150707 ymin: 3206375 xmax: 4152367 ymax: # 3208565 from to name type geometry weight <int> <int> <fct> <fct> <LINESTRING [m]> [m] 1 1 2 Havixbe~ resid~ (4151491 3207923, 4151474 3207~ 28.859~ 2 3 4 Pieners~ secon~ (4151398 3207777, 4151390 3207~ 107.714~ 3 5 6 Schulte~ resid~ (4151408 3207539, 4151417 3207~ 54.367~ 4 7 8 <NA> path (4151885 3206698, 4151861 3206~ 155.223~ 5 9 10 Welsing~ resid~ (4151732 3207017, 4151721 3206~ 208.682~ 6 11 12 <NA> footw~ (4152152 3206984, 4152143 3206~ 63.028~ # ... with 845 more rows # # Node Data: 701 x 1 # Geometry type: POINT # Dimension: XY # Bounding box: xmin: 4150707 ymin: 3206375 xmax: 4152367 ymax: # 3208565 geometry <POINT [m]> 1 (4151491 3207923) 2 (4151474 3207946) 3 (4151398 3207777) # ... with 698 more rows ``` ] --- class: split-40 count: false .left-panel-shortestpath1-user[ ```r net_proj %>% activate("edges") %>% mutate(weight = edge_length()) %>% * st_shortest_paths(p3, p4) %>% * .$vpath ``` ] .right-panel-shortestpath1-user[ ``` [[1]] + 45/701 vertices, from 90c0122: [1] 178 179 601 121 29 28 478 140 135 136 143 471 579 263 262 480 [17] 3 4 248 113 63 321 210 470 319 317 323 550 554 546 67 194 [33] 646 439 440 565 666 701 161 628 242 493 240 157 158 ``` ] <style> .left-panel-shortestpath1-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-shortestpath1-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-shortestpath1-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> .note[See issue [#54](https://github.com/luukvdmeer/sfnetworks/issues/54)] --- class: split-40 count: false .left-panel-morphers-user[ ```r *net %>% * morph(to_components) -> * net_m ``` ] .right-panel-morphers-user[ ] --- class: split-40 count: false .left-panel-morphers-user[ ```r net %>% morph(to_components) -> net_m *net_m %>% class() ``` ] .right-panel-morphers-user[ ``` [1] "morphed_sfnetwork" "morphed_tbl_graph" "list" ``` ] --- class: split-40 count: false .left-panel-morphers-user[ ```r net %>% morph(to_components) -> net_m net_m %>% class() *net_m %>% length() ``` ] .right-panel-morphers-user[ ``` [1] "morphed_sfnetwork" "morphed_tbl_graph" "list" ``` ``` [1] 14 ``` ] --- class: split-40 count: false .left-panel-morphers-user[ ```r net %>% morph(to_components) -> net_m net_m %>% class() net_m %>% length() *net %>% * convert(to_components, .select = 1) ``` ] .right-panel-morphers-user[ ``` [1] "morphed_sfnetwork" "morphed_tbl_graph" "list" ``` ``` [1] 14 ``` <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>675</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>838</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:4326</span><span> </span><span style='color: #555555;'> # # An undirected multigraph with 1 component with spatially explicit edges # # Node Data: 675 x 2 (active)</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> geometry .tidygraph_node_index </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;'>1</span><span> (7.533722 51.95556) 1 </span><span style='color: #555555;'>2</span><span> (7.533461 51.95576) 2 </span><span style='color: #555555;'>3</span><span> (7.532442 51.95422) 3 </span><span style='color: #555555;'>4</span><span> (7.53209 51.95328) 4 </span><span style='color: #555555;'>5</span><span> (7.532709 51.95209) 5 </span><span style='color: #555555;'>6</span><span> (7.532869 51.95257) 6 </span><span style='color: #555555;'># ... with 669 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 838 x 6</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> from to name type geometry .tidygraph_edge~ </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [°]></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havix~ resi~ (7.533722 51.95556, 7.533~ 1 </span><span style='color: #555555;'>2</span><span> 3 4 Piene~ seco~ (7.532442 51.95422, 7.532~ 2 </span><span style='color: #555555;'>3</span><span> 5 6 Schul~ resi~ (7.532709 51.95209, 7.532~ 3 </span><span style='color: #555555;'># ... with 835 more rows</span><span> </span></CODE></PRE> ] <style> .left-panel-morphers-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-morphers-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-morphers-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-spatialmorphers1-user[ ```r *net ``` ] .right-panel-spatialmorphers1-user[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>701</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>851</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:4326</span><span> </span><span style='color: #555555;'> # # An undirected multigraph with 14 components with spatially explicit edges # # Node Data: 701 x 1 (active)</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (7.533722 51.95556) </span><span style='color: #555555;'>2</span><span> (7.533461 51.95576) </span><span style='color: #555555;'>3</span><span> (7.532442 51.95422) </span><span style='color: #555555;'>4</span><span> (7.53209 51.95328) </span><span style='color: #555555;'>5</span><span> (7.532709 51.95209) </span><span style='color: #555555;'>6</span><span> (7.532869 51.95257) </span><span style='color: #555555;'># ... with 695 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 851 x 5</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> from to name type geometry </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [°]></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havixbecke~ reside~ (7.533722 51.95556, 7.533461 51.955~ </span><span style='color: #555555;'>2</span><span> 3 4 Pienersall~ second~ (7.532442 51.95422, 7.53236 51.9537~ </span><span style='color: #555555;'>3</span><span> 5 6 Schulte-Be~ reside~ (7.532709 51.95209, 7.532823 51.952~ </span><span style='color: #555555;'># ... with 848 more rows</span><span> </span></CODE></PRE> ] --- class: split-40 count: false .left-panel-spatialmorphers1-user[ ```r net %>% * convert(to_spatial_coordinates) ``` ] .right-panel-spatialmorphers1-user[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># A tbl_graph: 701 nodes and 851 edges # # An undirected multigraph with 14 components # # Node Data: 701 x 3 (active)</span><span> .tidygraph_node_index X Y </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><dbl></span><span> </span><span style='color: #555555;font-style: italic;'><dbl></span><span> </span><span style='color: #555555;'>1</span><span> 1 7.53 52.0 </span><span style='color: #555555;'>2</span><span> 2 7.53 52.0 </span><span style='color: #555555;'>3</span><span> 3 7.53 52.0 </span><span style='color: #555555;'>4</span><span> 4 7.53 52.0 </span><span style='color: #555555;'>5</span><span> 5 7.53 52.0 </span><span style='color: #555555;'>6</span><span> 6 7.53 52.0 </span><span style='color: #555555;'># ... with 695 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 851 x 5</span><span> from to name type .tidygraph_edge_index </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havixbecker Strasse residential 1 </span><span style='color: #555555;'>2</span><span> 3 4 Pienersallee secondary 2 </span><span style='color: #555555;'>3</span><span> 5 6 Schulte-Bernd-Strasse residential 3 </span><span style='color: #555555;'># ... with 848 more rows</span><span> </span></CODE></PRE> ] <style> .left-panel-spatialmorphers1-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-spatialmorphers1-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-spatialmorphers1-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-spatialmorphers2-user[ ```r *net %>% * convert(to_spatial_dense_graph) ``` ] .right-panel-spatialmorphers2-user[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># An sfnetwork with</span><span> </span><span style='color: #555555;'>1517</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>1692</span><span> </span><span style='color: #555555;'>edges # # CRS: </span><span> </span><span style='color: #555555;'>EPSG:4326</span><span> </span><span style='color: #555555;'> # # A directed simple graph with 1 component with spatially explicit edges # # Node Data: 1,517 x 1 (active)</span><span> </span><span style='color: #555555;'># Geometry type: POINT</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (7.533722 51.95556) </span><span style='color: #555555;'>2</span><span> (7.533461 51.95576) </span><span style='color: #555555;'>3</span><span> (7.53236 51.95377) </span><span style='color: #555555;'>4</span><span> (7.53209 51.95328) </span><span style='color: #555555;'>5</span><span> (7.532442 51.95422) </span><span style='color: #555555;'>6</span><span> (7.532823 51.95239) </span><span style='color: #555555;'># ... with 1,511 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 1,692 x 6</span><span> </span><span style='color: #555555;'># Geometry type: LINESTRING</span><span> </span><span style='color: #555555;'># Dimension: XY</span><span> </span><span style='color: #555555;'># Bounding box: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: # 51.9612</span><span> from to name type .tidygraph_edge~ geometry </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><fct></span><span> </span><span style='color: #555555;font-style: italic;'><int></span><span> </span><span style='color: #555555;font-style: italic;'><LINESTRING [°]></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 Havix~ resid~ 1 (7.533722 51.95556, 7.53~ </span><span style='color: #555555;'>2</span><span> 3 4 Piene~ secon~ 2 (7.53236 51.95377, 7.532~ </span><span style='color: #555555;'>3</span><span> 5 3 Piene~ secon~ 2 (7.532442 51.95422, 7.53~ </span><span style='color: #555555;'># ... with 1,689 more rows</span><span> </span></CODE></PRE> ] --- class: split-40 count: false .left-panel-spatialmorphers2-user[ ```r net %>% convert(to_spatial_dense_graph) %>% * plot() ``` ] .right-panel-spatialmorphers2-user[ <img src="slides_files/figure-html/spatialmorphers2_user_2_output-1.png" width="432" /> ] <style> .left-panel-spatialmorphers2-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-spatialmorphers2-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-spatialmorphers2-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-spatialmorphers3-user[ ```r *net_proj %>% * activate("edges") %>% * mutate(weight = edge_length()) %>% * convert(to_spatial_shortest_paths, p3, p4) ``` ] .right-panel-spatialmorphers3-user[ ``` # An sfnetwork with 45 nodes and 44 edges # # CRS: EPSG:3035 # # An unrooted tree with spatially explicit edges # # Edge Data: 44 x 7 (active) # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: 4150901 ymin: 3206483 xmax: 4152196 ymax: # 3208337 from to name type geometry weight <int> <int> <fct> <fct> <LINESTRING [m]> [m] 1 1 2 Pien~ seco~ (4151398 3207777, 415139~ 107.714~ 2 3 4 Bred~ resi~ (4151845 3208048, 415192~ 100.608~ 3 4 8 Bred~ resi~ (4152058 3208166, 415205~ 143.449~ 4 9 10 <NA> cycl~ (4151674 3207951, 415167~ 59.453~ 5 9 11 <NA> cycl~ (4151674 3207951, 415170~ 86.038~ 6 13 14 Lise~ resi~ (4151129 3206483, 415124~ 112.524~ # ... with 38 more rows, and 1 more variable: # .tidygraph_edge_index <int> # # Node Data: 45 x 2 # Geometry type: POINT # Dimension: XY # Bounding box: xmin: 4150901 ymin: 3206483 xmax: 4152196 ymax: # 3208337 geometry .tidygraph_node_index <POINT [m]> <int> 1 (4151398 3207777) 3 2 (4151370 3207673) 4 3 (4151845 3208048) 28 # ... with 42 more rows ``` ] --- class: split-40 count: false .left-panel-spatialmorphers3-user[ ```r net_proj %>% activate("edges") %>% mutate(weight = edge_length()) %>% convert(to_spatial_shortest_paths, p3, p4) -> * net_sp *par(mar = c(1,1,1,1), bg = NA) *plot(net_proj) ``` ] .right-panel-spatialmorphers3-user[ <img src="slides_files/figure-html/spatialmorphers3_user_2_output-1.png" width="432" /> ] --- class: split-40 count: false .left-panel-spatialmorphers3-user[ ```r net_proj %>% activate("edges") %>% mutate(weight = edge_length()) %>% convert(to_spatial_shortest_paths, p3, p4) -> net_sp par(mar = c(1,1,1,1), bg = NA) plot(net_proj) *plot(net_sp, * col = "Orange", lwd = 1.5, cex = 1.5, * add = T) ``` ] .right-panel-spatialmorphers3-user[ <img src="slides_files/figure-html/spatialmorphers3_user_3_output-1.png" width="432" /> ] <style> .left-panel-spatialmorphers3-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-spatialmorphers3-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-spatialmorphers3-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-spatialmorphers4-user[ ```r *net_proj %>% * morph(to_spatial_shortest_paths, p1, c(p3, p4)) ``` ] .right-panel-spatialmorphers4-user[ ``` # A tbl_graph temporarily morphed to a .f representation # # Original graph is an undirected multigraph with 14 components # consisting of 701 nodes and 851 edges ``` ] --- class: split-40 count: false .left-panel-spatialmorphers4-user[ ```r net_proj %>% morph(to_spatial_shortest_paths, p1, c(p3, p4)) %>% * activate("edges") %>% * sapply(function(x) sum(st_length(x))) ``` ] .right-panel-spatialmorphers4-user[ ``` [1] 1239.095 2651.979 ``` ] <style> .left-panel-spatialmorphers4-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-spatialmorphers4-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-spatialmorphers4-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-distancematrix-user[ ```r *ps1 = c(st_geometry(p1), st_sfc(p3)) *ps2 = c(st_geometry(p2), st_sfc(p4)) ``` ] .right-panel-distancematrix-user[ ] --- class: split-40 count: false .left-panel-distancematrix-user[ ```r ps1 = c(st_geometry(p1), st_sfc(p3)) ps2 = c(st_geometry(p2), st_sfc(p4)) *st_network_distance(net_proj, ps1, ps2) ``` ] .right-panel-distancematrix-user[ ``` [,1] [,2] [1,] 16 28 [2,] 23 35 ``` ] <style> .left-panel-distancematrix-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-panel-distancematrix-user { width: 60%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-distancematrix-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- ## Want more details? Check the package vignettes: - [Tidy Geospatial Networks in R](https://luukvdmeer.github.io/sfnetworks/articles/intro.html) - [Extending the vocabulary](https://luukvdmeer.github.io/sfnetworks/articles/extensions.html) --- background-image: url(https://pbs.twimg.com/media/EZvQNJlWoAE4D_c?format=jpg&name=4096x4096) # Applications -- <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> Many potential applications including: Transport planning/modelling (Robin), Road safety (Andrea), River network analysis (e.g. Water quality research, Flooding research, Aquatic ecology) Electricity network analysis, Social network analysis, Many More! --- ### How to cope with reduced public transport capacity post COVID-19? Plans from Leeds City Council responding to national [guidance](https://www.gov.uk/government/publications/reallocating-road-space-in-response-to-covid-19-statutory-guidance-for-local-authorities) and [funding](https://www.gov.uk/government/news/2-billion-package-to-create-new-era-for-cycling-and-walking) for 'pop-up' cycleways: ![](https://pbs.twimg.com/media/EZ_-A0dXgAAlBzt?format=png&name=900x900) --- ## Spatial networks can support planning ### Transport networks are spatial networks Spatial network representation in R: ![](https://raw.githubusercontent.com/cyipt/popupCycleways/master/figures/mapout.png) --- background-image: url("https://raw.githubusercontent.com/cyipt/popupCycleways/master/figures/facet-output.png") background-position: right background-size: contain -- ### sf + igraph used in project to support investment in 'pop-ups' nationwide Every city in England -- Results in Leeds: ``` name 1 Headingley Lane 2 A660 3 Woodhouse Lane 4 A65 5 Kirkstall Road ``` Cycleway planned for Kirkstall Road (source: [BBC](https://www.bbc.co.uk/news/uk-england-leeds-52577554)) Free and open results: [www.cyipt.bike/rapid](https://www.cyipt.bike/rapid) Source code: [github.com/cyipt/popupCycleways](https://github.com/cyipt/popupCycleways) <!-- ![](https://raw.githubusercontent.com/cyipt/popupCycleways/master/figures/facet-output.png) --> --- ## Ingredients to prioritise transport infrastructure .left-column[ - Current travel patterns - Road attribute data - Potential usage levels - Impact on overall network **Spatial networks can help, especially with the last two** Source: https://www.pct.bike/ ] .right-column[ ![](figs/pct.png) ] --- ## Why not use `stplanr::SpatialLinesNetwork`? .pull-left[ - You can: ```r r_stplanr = stplanr::SpatialLinesNetwork(roxel) ``` ```r l = stplanr::route_local(r_stplanr, c(7.53, 51.95), c(7.54, 51.95)) plot(r_stplanr@sl$geometry) plot(l$geometry, col = "red", lwd = 5, add = TRUE) ``` <img src="slides_files/figure-html/unnamed-chunk-8-1.png" width="432" /> ] .pull-right[ Issues with stplanr implementation: - `igraph` and `sf` parts are separate - Hard to access the nodes - Subsetting requires rebuilding the graph - Cannot modify CRS - It's difficult to perform spatial or regular joins ```r class(r_stplanr) ``` ``` [1] "sfNetwork" attr(,"package") [1] "stplanr" ``` ```r slotNames(r_stplanr) # s4 class system ``` ``` [1] "sl" "g" "nb" "weightfield" ``` ] --- ## Another example: formatting `sfnetwork` data for a road safety model We can use `sf`, `tidygraph`, `igraph` and several other packages for: -- - summarizing the spatial dimension of the road network using several metrics (`tidygraph`); -- - extracting the adjacency matrix of the edges, which is typically one of the ingredients in a spatial model (`igraph`); -- - subsetting the road network considering only a particular geographical area (`sf`). <!-- summarize the spatial dimension of the road network through several metrics and adjacency matrices. --> -- Let's see an example but first we need to create the `sfnetwork` version of `roxel` data: ```r net <- as_sfnetwork(roxel, directed = FALSE) ``` --- class: center, middle ### Summarizing Graph Characteristics --- class: split-40 count: false .left-panel-nodes_degree-user[ ```r # Estimate nodes centrality degree *net <- net ``` ] .right-panel-nodes_degree-user[ ] --- class: split-40 count: false .left-panel-nodes_degree-user[ ```r # Estimate nodes centrality degree net <- net %>% * activate("nodes") ``` ] .right-panel-nodes_degree-user[ ] --- class: split-40 count: false .left-panel-nodes_degree-user[ ```r # Estimate nodes centrality degree net <- net %>% activate("nodes") %>% * mutate(degree = centrality_degree()) ``` ] .right-panel-nodes_degree-user[ ] --- class: split-40 count: false .left-panel-nodes_degree-user[ ```r # Estimate nodes centrality degree net <- net %>% activate("nodes") %>% mutate(degree = centrality_degree()) # Plot with tmap. We need to escape the nodes and # edges dimension and rebuild the sf structure. *tm_shape(net %>% activate("edges") %>% st_as_sf()) + * tm_lines() ``` ] .right-panel-nodes_degree-user[ <img src="slides_files/figure-html/nodes_degree_user_4_output-1.png" width="432" /> ] --- class: split-40 count: false .left-panel-nodes_degree-user[ ```r # Estimate nodes centrality degree net <- net %>% activate("nodes") %>% mutate(degree = centrality_degree()) # Plot with tmap. We need to escape the nodes and # edges dimension and rebuild the sf structure. tm_shape(net %>% activate("edges") %>% st_as_sf()) + tm_lines() + *tm_shape(net %>% activate("nodes") %>% st_as_sf()) + * tm_dots( * size = 0.2, * col = "degree", * as.count = TRUE, * palette = "viridis", * title = "" * ) + *tm_layout(legend.text.size = 2) ``` ] .right-panel-nodes_degree-user[ <img src="slides_files/figure-html/nodes_degree_user_5_output-1.png" width="432" /> ] <style> .left-panel-nodes_degree-user { color: #777; width: 48%; height: 92%; float: left; font-size: 80% } .right-panel-nodes_degree-user { width: 50%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-nodes_degree-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-40 count: false .left-panel-edge_betweenness-user[ ```r # Estimate edges centrality betweenness *net <- net %>% * activate("edges") ``` ] .right-panel-edge_betweenness-user[ ] --- class: split-40 count: false .left-panel-edge_betweenness-user[ ```r # Estimate edges centrality betweenness net <- net %>% activate("edges") %>% * mutate( * lengths = st_length(.), * betweenness = centrality_edge_betweenness(lengths) * ) ``` ] .right-panel-edge_betweenness-user[ ] --- class: split-40 count: false .left-panel-edge_betweenness-user[ ```r # Estimate edges centrality betweenness net <- net %>% activate("edges") %>% mutate( lengths = st_length(.), betweenness = centrality_edge_betweenness(lengths) ) # Plot with tmap. We need to escape the nodes and # edges dimension and rebuild the sf structure. *tm_shape(net %>% activate("edges") %>% st_as_sf()) + * tm_lines( * n = 8, * scale = 2, * col = "betweenness", * palette = "viridis", * legend.col.show = FALSE * ) + *tm_shape(net %>% activate("nodes") %>% st_as_sf()) + * tm_dots(size = 0.1) ``` ] .right-panel-edge_betweenness-user[ <img src="slides_files/figure-html/edge_betweenness_user_3_output-1.png" width="432" /> ] <style> .left-panel-edge_betweenness-user { color: #777; width: 48%; height: 92%; float: left; font-size: 80% } .right-panel-edge_betweenness-user { width: 50%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-edge_betweenness-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- ### Extracting the Adjacency Matrix of the edges We can use `igraph` and `make_line_graph`! The `line graph` of a network object is obtained by inverting the nodes with the edges. We can apply this powerful idea to extract and visualize the `first-order binary adjacency matrix of the edges`. This type of matrix is used by a CAR or BYM spatial model. --- class: split-50 count: false ###First order binary adjacency .left-panel-line_graph-user[ ```r # Create the line graph *net_line_graph <- make_line_graph(net) ``` ] .right-panel-line_graph-user[ ] --- class: split-50 count: false ###First order binary adjacency .left-panel-line_graph-user[ ```r # Create the line graph net_line_graph <- make_line_graph(net) # Extract the first order binary adjacency matrix *first_order_binary_adjacency <- net_line_graph %>% * as_adjacency_matrix() ``` ] .right-panel-line_graph-user[ ] --- class: split-50 count: false ###First order binary adjacency .left-panel-line_graph-user[ ```r # Create the line graph net_line_graph <- make_line_graph(net) # Extract the first order binary adjacency matrix first_order_binary_adjacency <- net_line_graph %>% as_adjacency_matrix() *image( * first_order_binary_adjacency[sample(1:851), ], * xlab = list(label = "Columns", cex = 3), * ylab = list(label = "Row", cex = 3), * scales = list(cex = 3), * lwd = 3, * sub = "" * ) ``` ] .right-panel-line_graph-user[ <img src="slides_files/figure-html/line_graph_user_3_output-1.png" width="432" /> ] <style> .left-panel-line_graph-user { color: #777; width: 60%; height: 92%; float: left; font-size: 80% } .right-panel-line_graph-user { width: 35%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-line_graph-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: split-50 count: false ###Second order binary adjacency .left-panel-line_graph2-user[ ```r # Similar idea for second order binary adjacency *ego2_net <- ego(net_line_graph, 2) ``` ] .right-panel-line_graph2-user[ ] --- class: split-50 count: false ###Second order binary adjacency .left-panel-line_graph2-user[ ```r # Similar idea for second order binary adjacency ego2_net <- ego(net_line_graph, 2) *second_order_binary_adjacency <- ego2_net %>% * graph_from_adj_list() %>% * as_adjacency_matrix() ``` ] .right-panel-line_graph2-user[ ] --- class: split-50 count: false ###Second order binary adjacency .left-panel-line_graph2-user[ ```r # Similar idea for second order binary adjacency ego2_net <- ego(net_line_graph, 2) second_order_binary_adjacency <- ego2_net %>% graph_from_adj_list() %>% as_adjacency_matrix() *image( * second_order_binary_adjacency[sample(1:851), ], * xlab = list(label = "Columns", cex = 3), * ylab = list(label = "Row", cex = 3), * scales = list(cex = 3), * lwd = 3, * sub = "" * ) ``` ] .right-panel-line_graph2-user[ <img src="slides_files/figure-html/line_graph2_user_3_output-1.png" width="432" /> ] <style> .left-panel-line_graph2-user { color: #777; width: 60%; height: 92%; float: left; font-size: 80% } .right-panel-line_graph2-user { width: 35%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-line_graph2-user { width: 32%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: center, middle ### Thank you for you interest! #### Questions? .note[Slides powered by [xaringan](https://github.com/yihui/xaringan), [xaringanthemer](https://github.com/gadenbuie/xaringanthemer) and [flipbookr](https://github.com/EvaMaeRey/flipbookr)] --- background-image: url(https://github.com/sfnetworks/sfnetworks-webinar/raw/master/figs/e-Rum.png) ## See you tomorrow at e-Rum2020!