class: center, middle, inverse, title-slide # Introducción al paquete
sfnetworks
## Análisis de redes geoespaciales con R ### Lorena Abad ### 2021-01-15 --- class: center, middle, hide-logo <STYLE type='text/css' scoped> PRE.fansi SPAN {padding-top: .25em; padding-bottom: .25em}; </STYLE> ### Primero lo primero... Encuentran las diapositivas de la presentación aquí: https://sfnetworks.github.io/sfnetworks-REspacialES/slides ... y el código fuente en este repositorio de GitHub: https://github.com/sfnetworks/sfnetworks-REspacialES --- class: center, middle, hide-logo ## ¿De qué les voy a hablar hoy? Redes geoespaciales en R (sinópsis) Paquete `{sfnetworks}`: origen, filosofía, estructura Recorrido por las funciones de `{sfnetworks}`, incluyendo:<br> Las funciones base del paquete<br> Nuevas funciones en `{sfnetworks}` v.0.4.1 "Hiltrup" --- class: center, middle, hide-logo ## ¿Qué son redes geoespaciales? .pull-left[ Redes viales  ] .pull-right[ Redes fluviales  ] --- class: center, middle, hide-logo ## La oferta en R: -- .pull-left[ ### Análisis espacial [\#rspatial](https://twitter.com/search?q=%23rspatial) `sf` `stars` `rgeos` `rgdal` `tmap` `ggmap` `mapview` ... ] .pull-right[ ### Análisis de redes [statnet](http://statnet.org/) `igraph` `tidygraph` `qgraph` `ggraph` `visNetwork` `networkD3` ... ] --- class: center, middle, hide-logo # ¿Y para redes espaciales? -- [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, hide-logo ## Nuestra propuesta -- .pull-left[  ] -- .pull-right[  ] -- .center[  ] --- class: middle, hide-logo .pull-left-70[ .center[  ] .footnote[ Arte de [@allison_horst](https://twitter.com/allison_horst) ] ] .pull-right-30[ ### Datos *tidy* 1. Cada variable forma una columna. 2. Cada observación forma una fila. 3. Cada unidad observacional forma una tabla. .footnote[ Wickham, H. (2014). Tidy Data. Journal of Statistical Software, 59(10), 1 - 23. doi:http://dx.doi.org/10.18637/jss.v059.i10 ] <br> - Implementado en los paquetes *tidyverse* - Permite estructuras concatenables `%>%` - Más info en la charla de [REspacialEs aquí!](https://youtu.be/qm_30hOnocg) ] --- class: center, middle, hide-logo .pull-left-70[  .footnote[ Artwork by [@allison_horst](https://twitter.com/allison_horst) ] ] .pull-right-30[ ### ** Paquete `sf`** Simple features para R Datos espaciales vectoriales (puntos, líneas, polígonos) Compatible con los flujos *tidy* Clases S3 ] --- class: center, middle, hide-logo .pull-left-70[  .footnote[ Figura de [R Graph Gallery](https://www.r-graph-gallery.com/314-custom-circle-packing-with-several-levels.html) ] ] .pull-right-30[ ### **Paquete `tidygraph`**  Interfaz con [`igraph`](https://igraph.org/r/)  Soporte para *verbos* [`dplyr`](https://dplyr.tidyverse.org/)  Introduce nuevos *verbos* específicos para datos de redes (e.g. `morph`, `bind_graphs`, `graph_join`)  Permite visualizción a través de [`ggraph`](https://ggraph.data-imaginist.com/) ] --- class: center, middle # ¿Y `sfnetworks`? -- ### Filosofía De la introducción de `tidygraph`: > "... una cercana aproximación de datos *ordenados* para datos relacionales son dos *tidy data frames*, uno que describa los *nodos* y otro describiendo las *aristas*." -- <br> <br> > “Una cercana aproximación de datos *ordenados* para datos relacionales .orange[*geoespaciales*] son dos .orange[*objectos sf*], uno que describa los *nodos* y otro describiendo las *aristas*” adaptación para `sfnetworks`. --- class: middle ## Instalación Instalación estable desde GitHub en la rama `master`: ```r remotes::install_github("luukvdmeer/sfnetworks") ``` Instalación de la rama `develop` donde desarrollamos activamente el paquete y PR pueden ser dirigidas: ```r remotes::install_github("luukvdmeer/sfnetworks", ref = "develop") ``` --- class: middle ## Estructura de la clase `sfnetwork` ### Construcción Nodos: objeto `sf` con geometrías `POINT` Aristas: Columnas *to*, *from* y coordenadas de borde. Mismo sistema de coordenas! --- count: false ### Construcción .left-panel-toyexample-user[ ```r *library(sf) *library(sfnetworks) *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) ``` ] --- count: false ### Construcción .left-panel-toyexample-user[ ```r library(sf) library(sfnetworks) 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[ ] --- count: false ### Construcción .left-panel-toyexample-user[ ```r library(sf) library(sfnetworks) 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) ``` ] --- count: false ### Construcción .left-panel-toyexample-user[ ```r library(sf) library(sfnetworks) 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[ ] --- count: false ### Construcción .left-panel-toyexample-user[ ```r library(sf) library(sfnetworks) 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[ ] --- count: false ### Construcción .left-panel-toyexample-user[ ```r library(sf) library(sfnetworks) 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 if spatial network structure is valid... ``` ``` Spatial network structure is valid ``` <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># A 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> ] --- count: false ### Construcción .left-panel-toyexample-user[ ```r library(sf) library(sfnetworks) 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) -> * net ``` ] .right-panel-toyexample-user[ ``` Checking if spatial network structure is valid... ``` ``` Spatial network structure is valid ``` ] --- count: false ### Construcción .left-panel-toyexample-user[ ```r library(sf) library(sfnetworks) 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) -> net *class(net) ``` ] .right-panel-toyexample-user[ ``` Checking if spatial network structure is valid... ``` ``` Spatial network structure is valid ``` ``` [1] "sfnetwork" "tbl_graph" "igraph" ``` ] <style> .left-panel-toyexample-user { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-toyexample-user { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-toyexample-user { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false ### Tip extra! .left-panel-toyexamplename-user[ ```r *nodes$name = c("city", "village", "farm") *edges$from = c("city", "city", "village") *edges$to = c("village", "farm", "farm") ``` ] .right-panel-toyexamplename-user[ ] --- count: false ### Tip extra! .left-panel-toyexamplename-user[ ```r nodes$name = c("city", "village", "farm") edges$from = c("city", "city", "village") edges$to = c("village", "farm", "farm") *sfnetwork(nodes, edges, node_key = "name") ``` ] .right-panel-toyexamplename-user[ ``` Checking if spatial network structure is valid... ``` ``` Spatial network structure is valid ``` <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># A 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;'> # # A directed acyclic simple graph with 1 component with spatially explicit edges # # Node Data: 3 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 ymin: 51 xmax: 8 ymax: 52</span><span> geometry name </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;'>1</span><span> (7 51) city </span><span style='color: #555555;'>2</span><span> (7 52) village </span><span style='color: #555555;'>3</span><span> (8 52) farm </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-toyexamplename-user { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-toyexamplename-user { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-toyexamplename-user { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: middle ## Estructura de la clase `sfnetwork` ### Conversión Usando `as_sfnetwork()` se pueden pasar objetos de tipo: - `sf` con geometría `POINT` o `LINESTRING` - `tbl_graph` de `tidygraph` - `psp` o `linnet` de `spatstat` - `sfNetwork` de `stplanr` -- Archivos externos que se puedan leer con: - `sf::st_read()` - `igraph::read_graph() %>% as_tbl_graph()` --- #### Demo: Librerías ```r library(sf) library(sfnetworks) library(tidygraph) library(tidyverse) # Extras: library(ggplot2) ``` --- #### Demo: Datos .center[ <img src="slides_files/figure-html/demo2-1.png" width="864" /> ] --- #### Demo: Datos .center[ <img src="slides_files/figure-html/demo3-1.png" width="864" /> ] --- count: false #### Demo: Conversión .left-panel-demo4-rotate[ ```r cuenca %>% head() ``` ] .right-panel-demo4-rotate[ ``` Simple feature collection with 6 features and 6 fields geometry type: LINESTRING dimension: XY bbox: xmin: -79.03314 ymin: -2.906555 xmax: -78.95973 ymax: -2.888646 geographic CRS: WGS 84 name type lanes oneway sidewalk surface 1 <NA> residential <NA> no <NA> <NA> 2 <NA> trunk_link 1 yes right asphalt 3 Juan Montalvo residential 2 yes both sett 4 Miguel Heredia residential 2 yes both concrete 5 Miguel Velez residential 2 yes both concrete 6 Avenida de las Américas primary 2 yes <NA> asphalt geometry 1 LINESTRING (-79.028 -2.9061... 2 LINESTRING (-78.95973 -2.89... 3 LINESTRING (-79.00801 -2.89... 4 LINESTRING (-79.01274 -2.89... 5 LINESTRING (-79.01104 -2.89... 6 LINESTRING (-79.03314 -2.90... ``` ] --- count: false #### Demo: Conversión .left-panel-demo4-rotate[ ```r cuenca %>% * as_sfnetwork() ``` ] .right-panel-demo4-rotate[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># A sfnetwork with</span><span> </span><span style='color: #555555;'>12283</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>8999</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 3646 components with spatially explicit edges # # Node Data: 12,283 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: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (-79.028 -2.906154) </span><span style='color: #555555;'>2</span><span> (-79.02803 -2.90633) </span><span style='color: #555555;'>3</span><span> (-78.95973 -2.893506) </span><span style='color: #555555;'>4</span><span> (-78.96173 -2.893512) </span><span style='color: #555555;'>5</span><span> (-79.00801 -2.891764) </span><span style='color: #555555;'>6</span><span> (-79.00924 -2.89848) </span><span style='color: #555555;'># ... with 12,277 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 8,999 x 9</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: -79.08642 ymin: -2.960194 xmax: -78.90349 # ymax: -2.779669</span><span> from to name type lanes oneway sidewalk surface </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;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 </span><span style='color: #BB0000;'>NA</span><span> resi~ </span><span style='color: #BB0000;'>NA</span><span> no </span><span style='color: #BB0000;'>NA</span><span> </span><span style='color: #BB0000;'>NA</span><span> </span><span style='color: #555555;'>2</span><span> 3 4 </span><span style='color: #BB0000;'>NA</span><span> trun~ 1 yes right asphalt </span><span style='color: #555555;'>3</span><span> 5 6 Juan~ resi~ 2 yes both sett </span><span style='color: #555555;'># ... with 8,996 more rows, and 1 more variable: geometry </span><span style='color: #555555;font-style: italic;'><LINESTRING</span><span> </span><span style='color: #555555;'># </span><span style='color: #555555;font-style: italic;'> [°]></span><span> </span></CODE></PRE> ] <style> .left-panel-demo4-rotate { color: #777; width: 32.0388349514563%; height: 92%; float: left; font-size: 80% } .right-panel-demo4-rotate { width: 66.0194174757282%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo4-rotate { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false #### Demo: Conversión .left-panel-demo5-non_seq[ ```r cuenca %>% as_sfnetwork( ) ``` ] .right-panel-demo5-non_seq[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># A sfnetwork with</span><span> </span><span style='color: #555555;'>12283</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>8999</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 3646 components with spatially explicit edges # # Node Data: 12,283 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: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (-79.028 -2.906154) </span><span style='color: #555555;'>2</span><span> (-79.02803 -2.90633) </span><span style='color: #555555;'>3</span><span> (-78.95973 -2.893506) </span><span style='color: #555555;'>4</span><span> (-78.96173 -2.893512) </span><span style='color: #555555;'>5</span><span> (-79.00801 -2.891764) </span><span style='color: #555555;'>6</span><span> (-79.00924 -2.89848) </span><span style='color: #555555;'># ... with 12,277 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 8,999 x 9</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: -79.08642 ymin: -2.960194 xmax: -78.90349 # ymax: -2.779669</span><span> from to name type lanes oneway sidewalk surface </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;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 </span><span style='color: #BB0000;'>NA</span><span> resi~ </span><span style='color: #BB0000;'>NA</span><span> no </span><span style='color: #BB0000;'>NA</span><span> </span><span style='color: #BB0000;'>NA</span><span> </span><span style='color: #555555;'>2</span><span> 3 4 </span><span style='color: #BB0000;'>NA</span><span> trun~ 1 yes right asphalt </span><span style='color: #555555;'>3</span><span> 5 6 Juan~ resi~ 2 yes both sett </span><span style='color: #555555;'># ... with 8,996 more rows, and 1 more variable: geometry </span><span style='color: #555555;font-style: italic;'><LINESTRING</span><span> </span><span style='color: #555555;'># </span><span style='color: #555555;font-style: italic;'> [°]></span><span> </span></CODE></PRE> ] --- count: false #### Demo: Conversión .left-panel-demo5-non_seq[ ```r cuenca %>% as_sfnetwork( * directed = F, ) ``` ] .right-panel-demo5-non_seq[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># A sfnetwork with</span><span> </span><span style='color: #555555;'>12283</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>8999</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 3646 components with spatially explicit edges # # Node Data: 12,283 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: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (-79.028 -2.906154) </span><span style='color: #555555;'>2</span><span> (-79.02803 -2.90633) </span><span style='color: #555555;'>3</span><span> (-78.95973 -2.893506) </span><span style='color: #555555;'>4</span><span> (-78.96173 -2.893512) </span><span style='color: #555555;'>5</span><span> (-79.00801 -2.891764) </span><span style='color: #555555;'>6</span><span> (-79.00924 -2.89848) </span><span style='color: #555555;'># ... with 12,277 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 8,999 x 9</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: -79.08642 ymin: -2.960194 xmax: -78.90349 # ymax: -2.779669</span><span> from to name type lanes oneway sidewalk surface </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;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 </span><span style='color: #BB0000;'>NA</span><span> resi~ </span><span style='color: #BB0000;'>NA</span><span> no </span><span style='color: #BB0000;'>NA</span><span> </span><span style='color: #BB0000;'>NA</span><span> </span><span style='color: #555555;'>2</span><span> 3 4 </span><span style='color: #BB0000;'>NA</span><span> trun~ 1 yes right asphalt </span><span style='color: #555555;'>3</span><span> 5 6 Juan~ resi~ 2 yes both sett </span><span style='color: #555555;'># ... with 8,996 more rows, and 1 more variable: geometry </span><span style='color: #555555;font-style: italic;'><LINESTRING</span><span> </span><span style='color: #555555;'># </span><span style='color: #555555;font-style: italic;'> [°]></span><span> </span></CODE></PRE> ] --- count: false #### Demo: Conversión .left-panel-demo5-non_seq[ ```r cuenca %>% as_sfnetwork( directed = F, * edges_as_lines = F ) ``` ] .right-panel-demo5-non_seq[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># A sfnetwork with</span><span> </span><span style='color: #555555;'>12283</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>8999</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 3646 components with spatially implicit edges # # Node Data: 12,283 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: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (-79.028 -2.906154) </span><span style='color: #555555;'>2</span><span> (-79.02803 -2.90633) </span><span style='color: #555555;'>3</span><span> (-78.95973 -2.893506) </span><span style='color: #555555;'>4</span><span> (-78.96173 -2.893512) </span><span style='color: #555555;'>5</span><span> (-79.00801 -2.891764) </span><span style='color: #555555;'>6</span><span> (-79.00924 -2.89848) </span><span style='color: #555555;'># ... with 12,277 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 8,999 x 8</span><span> from to name type lanes oneway sidewalk surface </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;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 </span><span style='color: #BB0000;'>NA</span><span> residential </span><span style='color: #BB0000;'>NA</span><span> no </span><span style='color: #BB0000;'>NA</span><span> </span><span style='color: #BB0000;'>NA</span><span> </span><span style='color: #555555;'>2</span><span> 3 4 </span><span style='color: #BB0000;'>NA</span><span> trunk_link 1 yes right asphalt </span><span style='color: #555555;'>3</span><span> 5 6 Juan Montalvo residential 2 yes both sett </span><span style='color: #555555;'># ... with 8,996 more rows</span><span> </span></CODE></PRE> ] --- count: false #### Demo: Conversión .left-panel-demo5-non_seq[ ```r cuenca %>% as_sfnetwork( directed = F, edges_as_lines = F ) *net = as_sfnetwork(cuenca, directed = F) ``` ] .right-panel-demo5-non_seq[ <PRE class="fansi fansi-output"><CODE><span style='color: #555555;'># A sfnetwork with</span><span> </span><span style='color: #555555;'>12283</span><span> </span><span style='color: #555555;'>nodes and</span><span> </span><span style='color: #555555;'>8999</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 3646 components with spatially implicit edges # # Node Data: 12,283 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: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441</span><span> geometry </span><span style='color: #555555;font-style: italic;'><POINT [°]></span><span> </span><span style='color: #555555;'>1</span><span> (-79.028 -2.906154) </span><span style='color: #555555;'>2</span><span> (-79.02803 -2.90633) </span><span style='color: #555555;'>3</span><span> (-78.95973 -2.893506) </span><span style='color: #555555;'>4</span><span> (-78.96173 -2.893512) </span><span style='color: #555555;'>5</span><span> (-79.00801 -2.891764) </span><span style='color: #555555;'>6</span><span> (-79.00924 -2.89848) </span><span style='color: #555555;'># ... with 12,277 more rows</span><span> </span><span style='color: #555555;'># # Edge Data: 8,999 x 8</span><span> from to name type lanes oneway sidewalk surface </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;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;font-style: italic;'><chr></span><span> </span><span style='color: #555555;'>1</span><span> 1 2 </span><span style='color: #BB0000;'>NA</span><span> residential </span><span style='color: #BB0000;'>NA</span><span> no </span><span style='color: #BB0000;'>NA</span><span> </span><span style='color: #BB0000;'>NA</span><span> </span><span style='color: #555555;'>2</span><span> 3 4 </span><span style='color: #BB0000;'>NA</span><span> trunk_link 1 yes right asphalt </span><span style='color: #555555;'>3</span><span> 5 6 Juan Montalvo residential 2 yes both sett </span><span style='color: #555555;'># ... with 8,996 more rows</span><span> </span></CODE></PRE> ] <style> .left-panel-demo5-non_seq { color: #777; width: 32.0388349514563%; height: 92%; float: left; font-size: 80% } .right-panel-demo5-non_seq { width: 66.0194174757282%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo5-non_seq { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false #### Demo: Visualización .left-panel-demo6-user[ ```r *par(mar = c(0,0,0,0)) ``` ] .right-panel-demo6-user[ ] --- count: false #### Demo: Visualización .left-panel-demo6-user[ ```r par(mar = c(0,0,0,0)) *plot(net) ``` ] .right-panel-demo6-user[ <img src="slides_files/figure-html/demo6_user_2_output-1.png" width="864" /> ] <style> .left-panel-demo6-user { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-demo6-user { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo6-user { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false #### Demo: Visualización .left-panel-demo7-user[ ```r *autoplot(net) ``` ] .right-panel-demo7-user[ <img src="slides_files/figure-html/demo7_user_1_output-1.png" width="864" /> ] --- count: false #### Demo: Visualización .left-panel-demo7-user[ ```r autoplot(net) + * ggtitle("Red vial de Cuenca, Ecuador") ``` ] .right-panel-demo7-user[ <img src="slides_files/figure-html/demo7_user_2_output-1.png" width="864" /> ] <style> .left-panel-demo7-user { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-demo7-user { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo7-user { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> .note[[Issue en ggraph](https://github.com/thomasp85/ggraph/issues/275)] --- count: false #### Demo: Wrangling .left-panel-demo8-user[ ```r # Con verbos de `dplyr` *net ``` ] .right-panel-demo8-user[ ``` # A sfnetwork with 12283 nodes and 8999 edges # # CRS: EPSG:4326 # # An undirected multigraph with 3646 components with spatially explicit edges # # Node Data: 12,283 x 1 (active) # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441 geometry <POINT [°]> 1 (-79.028 -2.906154) 2 (-79.02803 -2.90633) 3 (-78.95973 -2.893506) 4 (-78.96173 -2.893512) 5 (-79.00801 -2.891764) 6 (-79.00924 -2.89848) # ... with 12,277 more rows # # Edge Data: 8,999 x 9 # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.08642 ymin: -2.960194 xmax: -78.90349 # ymax: -2.779669 from to name type lanes oneway sidewalk surface <int> <int> <chr> <chr> <chr> <chr> <chr> <chr> 1 1 2 <NA> resi~ <NA> no <NA> <NA> 2 3 4 <NA> trun~ 1 yes right asphalt 3 5 6 Juan~ resi~ 2 yes both sett # ... with 8,996 more rows, and 1 more variable: geometry <LINESTRING # [°]> ``` ] --- count: false #### Demo: Wrangling .left-panel-demo8-user[ ```r # Con verbos de `dplyr` net %>% * activate("edges") ``` ] .right-panel-demo8-user[ ``` # A sfnetwork with 12283 nodes and 8999 edges # # CRS: EPSG:4326 # # An undirected multigraph with 3646 components with spatially explicit edges # # Edge Data: 8,999 x 9 (active) # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.08642 ymin: -2.960194 xmax: -78.90349 # ymax: -2.779669 from to name type lanes oneway sidewalk surface <int> <int> <chr> <chr> <chr> <chr> <chr> <chr> 1 1 2 <NA> resi~ <NA> no <NA> <NA> 2 3 4 <NA> trun~ 1 yes right asphalt 3 5 6 Juan~ resi~ 2 yes both sett 4 7 8 Migu~ resi~ 2 yes both concre~ 5 9 10 Migu~ resi~ 2 yes both concre~ 6 11 12 Aven~ prim~ 2 yes <NA> asphalt # ... with 8,993 more rows, and 1 more variable: geometry <LINESTRING # [°]> # # Node Data: 12,283 x 1 # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441 geometry <POINT [°]> 1 (-79.028 -2.906154) 2 (-79.02803 -2.90633) 3 (-78.95973 -2.893506) # ... with 12,280 more rows ``` ] --- count: false #### Demo: Wrangling .left-panel-demo8-user[ ```r # Con verbos de `dplyr` net %>% activate("edges") %>% * filter(type == "residential") ``` ] .right-panel-demo8-user[ ``` # A sfnetwork with 12283 nodes and 4434 edges # # CRS: EPSG:4326 # # An undirected multigraph with 7890 components with spatially explicit edges # # Edge Data: 4,434 x 9 (active) # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.07054 ymin: -2.933674 xmax: -78.91342 # ymax: -2.83815 from to name type lanes oneway sidewalk surface <int> <int> <chr> <chr> <chr> <chr> <chr> <chr> 1 1 2 <NA> resi~ <NA> no <NA> <NA> 2 5 6 Juan~ resi~ 2 yes both sett 3 7 8 Migu~ resi~ 2 yes both concre~ 4 9 10 Migu~ resi~ 2 yes both concre~ 5 13 14 Cant~ resi~ 2 <NA> right concre~ 6 23 24 Moll~ resi~ 1 yes right asphalt # ... with 4,428 more rows, and 1 more variable: geometry <LINESTRING # [°]> # # Node Data: 12,283 x 1 # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441 geometry <POINT [°]> 1 (-79.028 -2.906154) 2 (-79.02803 -2.90633) 3 (-78.95973 -2.893506) # ... with 12,280 more rows ``` ] <style> .left-panel-demo8-user { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-demo8-user { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo8-user { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false #### Demo: Wrangling .left-panel-demo9-user[ ```r *par(mar = c(0,0,0,0), mfrow = c(2,1)) *plot(net, col = 'grey') ``` ] .right-panel-demo9-user[ <img src="slides_files/figure-html/demo9_user_1_output-1.png" width="864" /> ] --- count: false #### Demo: Wrangling .left-panel-demo9-user[ ```r par(mar = c(0,0,0,0), mfrow = c(2,1)) plot(net, col = 'grey') *plot( * sansebas, * border = 'red', lwd = 2, * col = NA, add = T *) ``` ] .right-panel-demo9-user[ <img src="slides_files/figure-html/demo9_user_2_output-1.png" width="864" /> ] --- count: false #### Demo: Wrangling .left-panel-demo9-user[ ```r par(mar = c(0,0,0,0), mfrow = c(2,1)) plot(net, col = 'grey') plot( sansebas, border = 'red', lwd = 2, col = NA, add = T ) *plot( * st_filter( * net, * sansebas, * .predicate = st_intersects * ) *) ``` ] .right-panel-demo9-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/demo9_user_3_output-1.png" width="864" /> ] <style> .left-panel-demo9-user { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-demo9-user { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo9-user { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false #### Demo: Wrangling .left-panel-demo10-user[ ```r # Con funciones de tidygraph *net %>% * activate("nodes") ``` ] .right-panel-demo10-user[ ``` # A sfnetwork with 12283 nodes and 8999 edges # # CRS: EPSG:4326 # # An undirected multigraph with 3646 components with spatially explicit edges # # Node Data: 12,283 x 1 (active) # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441 geometry <POINT [°]> 1 (-79.028 -2.906154) 2 (-79.02803 -2.90633) 3 (-78.95973 -2.893506) 4 (-78.96173 -2.893512) 5 (-79.00801 -2.891764) 6 (-79.00924 -2.89848) # ... with 12,277 more rows # # Edge Data: 8,999 x 9 # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.08642 ymin: -2.960194 xmax: -78.90349 # ymax: -2.779669 from to name type lanes oneway sidewalk surface <int> <int> <chr> <chr> <chr> <chr> <chr> <chr> 1 1 2 <NA> resi~ <NA> no <NA> <NA> 2 3 4 <NA> trun~ 1 yes right asphalt 3 5 6 Juan~ resi~ 2 yes both sett # ... with 8,996 more rows, and 1 more variable: geometry <LINESTRING # [°]> ``` ] --- count: false #### Demo: Wrangling .left-panel-demo10-user[ ```r # Con funciones de tidygraph net %>% activate("nodes") %>% * mutate(centrality = centrality_betweenness()) ``` ] .right-panel-demo10-user[ ``` # A sfnetwork with 12283 nodes and 8999 edges # # CRS: EPSG:4326 # # An undirected multigraph with 3646 components with spatially explicit edges # # Node Data: 12,283 x 2 (active) # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441 geometry centrality <POINT [°]> <dbl> 1 (-79.028 -2.906154) 0 2 (-79.02803 -2.90633) 0 3 (-78.95973 -2.893506) 9171 4 (-78.96173 -2.893512) 18332 5 (-79.00801 -2.891764) 99891 6 (-79.00924 -2.89848) 102884 # ... with 12,277 more rows # # Edge Data: 8,999 x 9 # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.08642 ymin: -2.960194 xmax: -78.90349 # ymax: -2.779669 from to name type lanes oneway sidewalk surface <int> <int> <chr> <chr> <chr> <chr> <chr> <chr> 1 1 2 <NA> resi~ <NA> no <NA> <NA> 2 3 4 <NA> trun~ 1 yes right asphalt 3 5 6 Juan~ resi~ 2 yes both sett # ... with 8,996 more rows, and 1 more variable: geometry <LINESTRING # [°]> ``` ] <style> .left-panel-demo10-user { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-demo10-user { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo10-user { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false #### Demo: Wrangling .left-panel-demo11-non_seq[ ```r # Funciones especificas para redes espaciales net %>% activate("edges") %>% select(to, from, geometry) %>% mutate( ) ``` ] .right-panel-demo11-non_seq[ ``` # A sfnetwork with 12283 nodes and 8999 edges # # CRS: EPSG:4326 # # An undirected multigraph with 3646 components with spatially explicit edges # # Edge Data: 8,999 x 3 (active) # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.08642 ymin: -2.960194 xmax: -78.90349 # ymax: -2.779669 from to geometry <int> <int> <LINESTRING [°]> 1 1 2 (-79.028 -2.906154, -79.02803 -2.90633) 2 3 4 (-78.95973 -2.893506, -78.96027 -2.893746, -78.96056 -2~ 3 5 6 (-79.00801 -2.891764, -79.00819 -2.892754, -79.00834 -2~ 4 7 8 (-79.01274 -2.894131, -79.01278 -2.894429, -79.01283 -2~ 5 9 10 (-79.01104 -2.891014, -79.01095 -2.890318, -79.01093 -2~ 6 11 12 (-79.03314 -2.906555, -79.03292 -2.906139, -79.03261 -2~ # ... with 8,993 more rows # # Node Data: 12,283 x 1 # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441 geometry <POINT [°]> 1 (-79.028 -2.906154) 2 (-79.02803 -2.90633) 3 (-78.95973 -2.893506) # ... with 12,280 more rows ``` ] --- count: false #### Demo: Wrangling .left-panel-demo11-non_seq[ ```r # Funciones especificas para redes espaciales net %>% activate("edges") %>% select(to, from, geometry) %>% mutate( * length = edge_length(), ) ``` ] .right-panel-demo11-non_seq[ ``` # A sfnetwork with 12283 nodes and 8999 edges # # CRS: EPSG:4326 # # An undirected multigraph with 3646 components with spatially explicit edges # # Edge Data: 8,999 x 4 (active) # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.08642 ymin: -2.960194 xmax: -78.90349 # ymax: -2.779669 from to geometry length <int> <int> <LINESTRING [°]> [m] 1 1 2 (-79.028 -2.906154, -79.02803 -2.90633) 19.663~ 2 3 4 (-78.95973 -2.893506, -78.96027 -2.893746, -78~ 241.638~ 3 5 6 (-79.00801 -2.891764, -79.00819 -2.892754, -79~ 757.311~ 4 7 8 (-79.01274 -2.894131, -79.01278 -2.894429, -79~ 138.144~ 5 9 10 (-79.01104 -2.891014, -79.01095 -2.890318, -79~ 271.476~ 6 11 12 (-79.03314 -2.906555, -79.03292 -2.906139, -79~ 347.195~ # ... with 8,993 more rows # # Node Data: 12,283 x 1 # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441 geometry <POINT [°]> 1 (-79.028 -2.906154) 2 (-79.02803 -2.90633) 3 (-78.95973 -2.893506) # ... with 12,280 more rows ``` ] --- count: false #### Demo: Wrangling .left-panel-demo11-non_seq[ ```r # Funciones especificas para redes espaciales net %>% activate("edges") %>% select(to, from, geometry) %>% mutate( length = edge_length(), * azimuth = edge_azimuth() ) ``` ] .right-panel-demo11-non_seq[ ``` # A sfnetwork with 12283 nodes and 8999 edges # # CRS: EPSG:4326 # # An undirected multigraph with 3646 components with spatially explicit edges # # Edge Data: 8,999 x 5 (active) # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.08642 ymin: -2.960194 xmax: -78.90349 # ymax: -2.779669 from to geometry length azimuth <int> <int> <LINESTRING [°]> [m] [rad] 1 1 2 (-79.028 -2.906154, -79.02803 -2.9063~ 19.663~ -2.9906~ 2 3 4 (-78.95973 -2.893506, -78.96027 -2.89~ 241.638~ -1.5740~ 3 5 6 (-79.00801 -2.891764, -79.00819 -2.89~ 757.311~ -2.9590~ 4 7 8 (-79.01274 -2.894131, -79.01278 -2.89~ 138.144~ -2.9463~ 5 9 10 (-79.01104 -2.891014, -79.01095 -2.89~ 271.476~ -0.1295~ 6 11 12 (-79.03314 -2.906555, -79.03292 -2.90~ 347.195~ 0.5731~ # ... with 8,993 more rows # # Node Data: 12,283 x 1 # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441 geometry <POINT [°]> 1 (-79.028 -2.906154) 2 (-79.02803 -2.90633) 3 (-78.95973 -2.893506) # ... with 12,280 more rows ``` ] <style> .left-panel-demo11-non_seq { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-demo11-non_seq { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo11-non_seq { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false #### Demo: Preprocesamiento .left-panel-demo13-non_seq[ ```r net %>% st_filter(gilramir, .predicate = st_intersects) %>% plot() ``` ] .right-panel-demo13-non_seq[ ``` 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/demo13_non_seq_1_output-1.png" width="864" /> ] --- count: false #### Demo: Preprocesamiento .left-panel-demo13-non_seq[ ```r net %>% st_filter(gilramir, .predicate = st_intersects) %>% * convert(to_spatial_subdivision) %>% plot() ``` ] .right-panel-demo13-non_seq[ ``` 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/demo13_non_seq_2_output-1.png" width="864" /> ] --- count: false #### Demo: Preprocesamiento .left-panel-demo13-non_seq[ ```r net %>% st_filter(gilramir, .predicate = st_intersects) %>% convert(to_spatial_subdivision) %>% * convert(to_spatial_smooth) %>% plot() ``` ] .right-panel-demo13-non_seq[ ``` 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/demo13_non_seq_3_output-1.png" width="864" /> ] --- count: false #### Demo: Preprocesamiento .left-panel-demo13-non_seq[ ```r net %>% st_filter(gilramir, .predicate = st_intersects) %>% convert(to_spatial_subdivision) %>% convert(to_spatial_smooth) %>% * convert(to_spatial_simple) %>% plot() ``` ] .right-panel-demo13-non_seq[ ``` 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/demo13_non_seq_4_output-1.png" width="864" /> ] <style> .left-panel-demo13-non_seq { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-demo13-non_seq { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo13-non_seq { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false #### Demo: Preprocesamiento .left-panel-demo14-user[ ```r *net ``` ] .right-panel-demo14-user[ ``` # A sfnetwork with 12283 nodes and 8999 edges # # CRS: EPSG:4326 # # An undirected multigraph with 3646 components with spatially explicit edges # # Node Data: 12,283 x 1 (active) # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.935008 xmax: -78.91145 ymax: # -2.833441 geometry <POINT [°]> 1 (-79.028 -2.906154) 2 (-79.02803 -2.90633) 3 (-78.95973 -2.893506) 4 (-78.96173 -2.893512) 5 (-79.00801 -2.891764) 6 (-79.00924 -2.89848) # ... with 12,277 more rows # # Edge Data: 8,999 x 9 # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.08642 ymin: -2.960194 xmax: -78.90349 # ymax: -2.779669 from to name type lanes oneway sidewalk surface <int> <int> <chr> <chr> <chr> <chr> <chr> <chr> 1 1 2 <NA> resi~ <NA> no <NA> <NA> 2 3 4 <NA> trun~ 1 yes right asphalt 3 5 6 Juan~ resi~ 2 yes both sett # ... with 8,996 more rows, and 1 more variable: geometry <LINESTRING # [°]> ``` ] --- count: false #### Demo: Preprocesamiento .left-panel-demo14-user[ ```r net %>% * convert(to_spatial_subdivision) %>% * convert(to_spatial_smooth) %>% * convert(to_spatial_simple) ``` ] .right-panel-demo14-user[ ``` # A sfnetwork with 11799 nodes and 15772 edges # # CRS: EPSG:4326 # # An undirected simple graph with 125 components with spatially explicit edges # # Node Data: 11,799 x 2 (active) # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.934974 xmax: -78.91145 ymax: # -2.833441 geometry .tidygraph_node_index <POINT [°]> <int> 1 (-79.028 -2.906154) 1 2 (-79.02803 -2.90633) 2 3 (-78.96027 -2.893746) 3 4 (-78.96173 -2.893512) 4 5 (-79.00801 -2.891764) 5 6 (-79.00819 -2.892754) 6 # ... with 11,793 more rows # # Edge Data: 15,772 x 10 # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.935125 xmax: -78.91145 ymax: # -2.833441 from to name type lanes oneway sidewalk surface <int> <int> <chr> <chr> <chr> <chr> <chr> <chr> 1 1 2 <NA> resi~ <NA> no <NA> <NA> 2 3 4 <NA> trun~ 1 yes right asphalt 3 5 6 Juan~ resi~ 2 yes both sett # ... with 15,769 more rows, and 2 more variables: # geometry <LINESTRING [°]>, .tidygraph_edge_index <int> ``` ] --- count: false #### Demo: Preprocesamiento .left-panel-demo14-user[ ```r net %>% convert(to_spatial_subdivision) %>% convert(to_spatial_smooth) %>% convert(to_spatial_simple) -> * net_clean ``` ] .right-panel-demo14-user[ ] <style> .left-panel-demo14-user { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-demo14-user { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo14-user { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false #### Demo: Ruteo .left-panel-demo15-user[ ```r *parque = st_sfc(st_point(c(-79.0044, -2.8977)), crs = 4326) *artes = st_sfc(st_point(c(-79.0252, -2.9203)), crs= 4326) *estadio = st_sfc(st_point(c(-79.00586, -2.90672)), crs= 4326) ``` ] .right-panel-demo15-user[ ] --- count: false #### Demo: Ruteo .left-panel-demo15-user[ ```r parque = st_sfc(st_point(c(-79.0044, -2.8977)), crs = 4326) artes = st_sfc(st_point(c(-79.0252, -2.9203)), crs= 4326) estadio = st_sfc(st_point(c(-79.00586, -2.90672)), crs= 4326) *st_network_paths( * net_clean, * from = parque, * to = c(artes,estadio) *) ``` ] .right-panel-demo15-user[ ``` although coordinates are longitude/latitude, st_nearest_points assumes that they are planar although coordinates are longitude/latitude, st_nearest_points assumes that they are planar ``` ``` # A tibble: 2 x 2 node_paths edge_paths <list> <list> 1 <int [66]> <int [65]> 2 <int [22]> <int [21]> ``` ] --- count: false #### Demo: Ruteo .left-panel-demo15-user[ ```r parque = st_sfc(st_point(c(-79.0044, -2.8977)), crs = 4326) artes = st_sfc(st_point(c(-79.0252, -2.9203)), crs= 4326) estadio = st_sfc(st_point(c(-79.00586, -2.90672)), crs= 4326) st_network_paths( net_clean, from = parque, to = c(artes,estadio) ) -> * paths *paths %>% * pull(node_paths) %>% * unlist() ``` ] .right-panel-demo15-user[ ``` although coordinates are longitude/latitude, st_nearest_points assumes that they are planar although coordinates are longitude/latitude, st_nearest_points assumes that they are planar ``` ``` [1] 11045 8088 8087 8078 238 278 2629 6777 6205 6775 6776 [12] 205 10276 10384 8955 1063 1062 3885 675 676 2646 1085 [23] 1097 6250 8761 9982 2034 617 646 684 638 606 6778 [34] 559 560 561 9640 247 248 4213 3791 3818 3761 4913 [45] 4911 4857 4603 3764 6316 4898 6324 8100 4897 4841 3835 [56] 3834 10931 4842 4893 4892 4891 4826 717 716 7503 7504 [67] 11045 8088 8087 8078 238 278 2629 6777 6205 6775 6776 [78] 205 2038 8789 8788 817 821 793 8787 214 213 8785 ``` ] <style> .left-panel-demo15-user { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-demo15-user { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo15-user { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false #### Demo: Ruteo .left-panel-demo18-user[ ```r *plot_path = function(node_path) { * net_clean %>% * activate("nodes") %>% * slice(node_path) %>% * plot(cex = 1.5, lwd = 1.5, add = TRUE) *} ``` ] .right-panel-demo18-user[ ] --- count: false #### Demo: Ruteo .left-panel-demo18-user[ ```r plot_path = function(node_path) { net_clean %>% activate("nodes") %>% slice(node_path) %>% plot(cex = 1.5, lwd = 1.5, add = TRUE) } *par(mar = c(0,0,0,0), mfrow = c(1,1)) *plot(net_clean, col = 'grey') ``` ] .right-panel-demo18-user[ <img src="slides_files/figure-html/demo18_user_2_output-1.png" width="864" /> ] --- count: false #### Demo: Ruteo .left-panel-demo18-user[ ```r plot_path = function(node_path) { net_clean %>% activate("nodes") %>% slice(node_path) %>% plot(cex = 1.5, lwd = 1.5, add = TRUE) } par(mar = c(0,0,0,0), mfrow = c(1,1)) plot(net_clean, col = 'grey') *plot(parque, col = "blue", pch = 8, add = T) *plot(artes, col = "red", pch = 8, add = T) *plot(estadio, col = "orange", pch = 8, add = T) ``` ] .right-panel-demo18-user[ <img src="slides_files/figure-html/demo18_user_3_output-1.png" width="864" /> ] --- count: false #### Demo: Ruteo .left-panel-demo18-user[ ```r plot_path = function(node_path) { net_clean %>% activate("nodes") %>% slice(node_path) %>% plot(cex = 1.5, lwd = 1.5, add = TRUE) } par(mar = c(0,0,0,0), mfrow = c(1,1)) plot(net_clean, col = 'grey') plot(parque, col = "blue", pch = 8, add = T) plot(artes, col = "red", pch = 8, add = T) plot(estadio, col = "orange", pch = 8, add = T) *paths %>% * pull(node_paths) %>% * purrr::walk(plot_path) ``` ] .right-panel-demo18-user[ <img src="slides_files/figure-html/demo18_user_4_output-1.png" width="864" /> ] <style> .left-panel-demo18-user { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-demo18-user { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo18-user { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false #### Demo: Isocronas .left-panel-demo16-user[ ```r *net_clean %>% * activate("edges") %>% * pull(type) %>% * unique() ``` ] .right-panel-demo16-user[ ``` [1] "residential" "trunk_link" "primary" [4] "secondary" "tertiary" "trunk" [7] "cycleway" "secondary_link" "steps" [10] "pedestrian" "primary_link" "living_street" [13] "footway" "path" "service" [16] "track" "unclassified" "tertiary_link" [19] NA ``` ] --- count: false #### Demo: Isocronas .left-panel-demo16-user[ ```r net_clean %>% activate("edges") %>% pull(type) %>% unique() -> * types # Randomly define a walking speed in m/s for each type, # with values between 3 and 7 km/h. *set.seed(1) *speeds = runif( * length(types), * 3 * 1000 / 60 / 60, * 7 * 1000 / 60 / 60 *) ``` ] .right-panel-demo16-user[ ] --- count: false #### Demo: Isocronas .left-panel-demo16-user[ ```r net_clean %>% activate("edges") %>% pull(type) %>% unique() -> types # Randomly define a walking speed in m/s for each type, # with values between 3 and 7 km/h. set.seed(1) speeds = runif( length(types), 3 * 1000 / 60 / 60, 7 * 1000 / 60 / 60 ) # Assign a speed to each edge based on its type. # Calculate travel time for each edge based on that. *net_clean %>% * activate("edges") %>% * select(type) %>% * mutate(weight = edge_length()) %>% * group_by(type) %>% * mutate(speed = units::set_units(speeds[cur_group_id()], "m/s")) %>% * mutate(time = weight / speed) %>% * ungroup() ``` ] .right-panel-demo16-user[ ``` # A sfnetwork with 11799 nodes and 15772 edges # # CRS: EPSG:4326 # # An undirected simple graph with 125 components with spatially explicit edges # # Edge Data: 15,772 x 7 (active) # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.935125 xmax: -78.91145 ymax: # -2.833441 from to type geometry weight speed <int> <int> <chr> <LINESTRING [°]> [m] [m/s] 1 1 2 resi~ (-79.028 -2.906154, -79.~ 19.663~ 1.567553 2 3 4 trun~ (-78.96027 -2.893746, -7~ 176.811~ 1.630687 3 5 6 resi~ (-79.00801 -2.891764, -7~ 111.254~ 1.567553 4 6 7 resi~ (-79.00819 -2.892754, -7~ 115.074~ 1.567553 5 7 8 resi~ (-79.00834 -2.893783, -7~ 3.983~ 1.567553 6 8 9 resi~ (-79.00837 -2.893797, -7~ 114.482~ 1.567553 # ... with 15,766 more rows, and 1 more variable: time [s] # # Node Data: 11,799 x 2 # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.934974 xmax: -78.91145 ymax: # -2.833441 geometry .tidygraph_node_index <POINT [°]> <int> 1 (-79.028 -2.906154) 1 2 (-79.02803 -2.90633) 2 3 (-78.96027 -2.893746) 3 # ... with 11,796 more rows ``` ] --- count: false #### Demo: Isocronas .left-panel-demo16-user[ ```r net_clean %>% activate("edges") %>% pull(type) %>% unique() -> types # Randomly define a walking speed in m/s for each type, # with values between 3 and 7 km/h. set.seed(1) speeds = runif( length(types), 3 * 1000 / 60 / 60, 7 * 1000 / 60 / 60 ) # Assign a speed to each edge based on its type. # Calculate travel time for each edge based on that. net_clean %>% activate("edges") %>% select(type) %>% mutate(weight = edge_length()) %>% group_by(type) %>% mutate(speed = units::set_units(speeds[cur_group_id()], "m/s")) %>% mutate(time = weight / speed) %>% ungroup() %>% * activate("nodes") -> * net_clean ``` ] .right-panel-demo16-user[ ] <style> .left-panel-demo16-user { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-demo16-user { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo16-user { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false #### Demo: Isocronas .left-panel-demo17-user[ ```r *net_clean %>% * filter( * node_distance_from( * st_nearest_feature(parque, net_clean), * weights = time) <= 600 * ) ``` ] .right-panel-demo17-user[ ``` although coordinates are longitude/latitude, st_nearest_points assumes that they are planar ``` ``` # A sfnetwork with 343 nodes and 494 edges # # CRS: EPSG:4326 # # An undirected simple graph with 1 component with spatially explicit edges # # Node Data: 343 x 2 (active) # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.01202 ymin: -2.90453 xmax: -78.99676 ymax: # -2.889817 geometry .tidygraph_node_index <POINT [°]> <int> 1 (-79.00834 -2.893783) 7 2 (-79.00837 -2.893797) 8 3 (-79.00857 -2.894813) 9 4 (-79.00875 -2.895823) 10 5 (-79.00892 -2.896779) 11 6 (-79.00911 -2.897794) 12 # ... with 337 more rows # # Edge Data: 494 x 7 # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.01202 ymin: -2.90453 xmax: -78.99676 ymax: # -2.889817 from to type geometry weight speed <int> <int> <chr> <LINESTRING [°]> [m] [m/s] 1 1 2 resi~ (-79.00834 -2.893783, -7~ 3.983~ 1.567553 2 2 3 resi~ (-79.00837 -2.893797, -7~ 114.482~ 1.567553 3 3 4 resi~ (-79.00857 -2.894813, -7~ 113.555~ 1.567553 # ... with 491 more rows, and 1 more variable: time [s] ``` ] --- count: false #### Demo: Isocronas .left-panel-demo17-user[ ```r net_clean %>% filter( node_distance_from( st_nearest_feature(parque, net_clean), weights = time) <= 600 ) -> * iso *iso_poly = iso %>% * st_geometry() %>% * st_union() %>% * st_convex_hull() ``` ] .right-panel-demo17-user[ ``` although coordinates are longitude/latitude, st_nearest_points assumes that they are planar ``` ``` although coordinates are longitude/latitude, st_union assumes that they are planar ``` ] --- count: false #### Demo: Isocronas .left-panel-demo17-user[ ```r net_clean %>% filter( node_distance_from( st_nearest_feature(parque, net_clean), weights = time) <= 600 ) -> iso iso_poly = iso %>% st_geometry() %>% st_union() %>% st_convex_hull() *par(mar = c(0,0,0,0), mfrow = c(1,1)) *plot(net_clean, col = "grey") ``` ] .right-panel-demo17-user[ ``` although coordinates are longitude/latitude, st_nearest_points assumes that they are planar ``` ``` although coordinates are longitude/latitude, st_union assumes that they are planar ``` <img src="slides_files/figure-html/demo17_user_3_output-1.png" width="864" /> ] --- count: false #### Demo: Isocronas .left-panel-demo17-user[ ```r net_clean %>% filter( node_distance_from( st_nearest_feature(parque, net_clean), weights = time) <= 600 ) -> iso iso_poly = iso %>% st_geometry() %>% st_union() %>% st_convex_hull() par(mar = c(0,0,0,0), mfrow = c(1,1)) plot(net_clean, col = "grey") *plot( * iso_poly, * col = NA, border = "black", * lwd = 3, add = TRUE) ``` ] .right-panel-demo17-user[ ``` although coordinates are longitude/latitude, st_nearest_points assumes that they are planar ``` ``` although coordinates are longitude/latitude, st_union assumes that they are planar ``` <img src="slides_files/figure-html/demo17_user_4_output-1.png" width="864" /> ] --- count: false #### Demo: Isocronas .left-panel-demo17-user[ ```r net_clean %>% filter( node_distance_from( st_nearest_feature(parque, net_clean), weights = time) <= 600 ) -> iso iso_poly = iso %>% st_geometry() %>% st_union() %>% st_convex_hull() par(mar = c(0,0,0,0), mfrow = c(1,1)) plot(net_clean, col = "grey") plot( iso_poly, col = NA, border = "black", lwd = 3, add = TRUE) *plot(iso, * col = "lightsalmon", * add = TRUE) ``` ] .right-panel-demo17-user[ ``` although coordinates are longitude/latitude, st_nearest_points assumes that they are planar ``` ``` although coordinates are longitude/latitude, st_union assumes that they are planar ``` <img src="slides_files/figure-html/demo17_user_5_output-1.png" width="864" /> ] --- count: false #### Demo: Isocronas .left-panel-demo17-user[ ```r net_clean %>% filter( node_distance_from( st_nearest_feature(parque, net_clean), weights = time) <= 600 ) -> iso iso_poly = iso %>% st_geometry() %>% st_union() %>% st_convex_hull() par(mar = c(0,0,0,0), mfrow = c(1,1)) plot(net_clean, col = "grey") plot( iso_poly, col = NA, border = "black", lwd = 3, add = TRUE) plot(iso, col = "lightsalmon", add = TRUE) *plot(parque, col = "blue", * pch = 8, cex = 2, * lwd = 2, add = TRUE) ``` ] .right-panel-demo17-user[ ``` although coordinates are longitude/latitude, st_nearest_points assumes that they are planar ``` ``` although coordinates are longitude/latitude, st_union assumes that they are planar ``` <img src="slides_files/figure-html/demo17_user_6_output-1.png" width="864" /> ] <style> .left-panel-demo17-user { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-demo17-user { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo17-user { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false #### Demo: Detección de comunidades .left-panel-demo12-user[ ```r *net_clean ``` ] .right-panel-demo12-user[ ``` # A sfnetwork with 11799 nodes and 15772 edges # # CRS: EPSG:4326 # # An undirected simple graph with 125 components with spatially explicit edges # # Node Data: 11,799 x 2 (active) # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.934974 xmax: -78.91145 ymax: # -2.833441 geometry .tidygraph_node_index <POINT [°]> <int> 1 (-79.028 -2.906154) 1 2 (-79.02803 -2.90633) 2 3 (-78.96027 -2.893746) 3 4 (-78.96173 -2.893512) 4 5 (-79.00801 -2.891764) 5 6 (-79.00819 -2.892754) 6 # ... with 11,793 more rows # # Edge Data: 15,772 x 10 # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.935125 xmax: -78.91145 ymax: # -2.833441 from to name type lanes oneway sidewalk surface <int> <int> <chr> <chr> <chr> <chr> <chr> <chr> 1 1 2 <NA> resi~ <NA> no <NA> <NA> 2 3 4 <NA> trun~ 1 yes right asphalt 3 5 6 Juan~ resi~ 2 yes both sett # ... with 15,769 more rows, and 2 more variables: # geometry <LINESTRING [°]>, .tidygraph_edge_index <int> ``` ] --- count: false #### Demo: Detección de comunidades .left-panel-demo12-user[ ```r net_clean %>% * morph(to_linegraph) ``` ] .right-panel-demo12-user[ ``` # A tbl_graph temporarily morphed to a linegraph representation # # Original graph is an undirected simple graph with 125 components # consisting of 11799 nodes and 15772 edges ``` ] --- count: false #### Demo: Detección de comunidades .left-panel-demo12-user[ ```r net_clean %>% morph(to_linegraph) %>% * mutate(group = group_louvain()) ``` ] .right-panel-demo12-user[ ``` # A tbl_graph temporarily morphed to a linegraph representation # # Original graph is an undirected simple graph with 125 components # consisting of 11799 nodes and 15772 edges ``` ] --- count: false #### Demo: Detección de comunidades .left-panel-demo12-user[ ```r net_clean %>% morph(to_linegraph) %>% mutate(group = group_louvain()) %>% * unmorph() ``` ] .right-panel-demo12-user[ ``` # A sfnetwork with 11799 nodes and 15772 edges # # CRS: EPSG:4326 # # An undirected simple graph with 125 components with spatially explicit edges # # Node Data: 11,799 x 1 (active) # Geometry type: POINT # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.934974 xmax: -78.91145 ymax: # -2.833441 geometry <POINT [°]> 1 (-79.028 -2.906154) 2 (-79.02803 -2.90633) 3 (-78.96027 -2.893746) 4 (-78.96173 -2.893512) 5 (-79.00801 -2.891764) 6 (-79.00819 -2.892754) # ... with 11,793 more rows # # Edge Data: 15,772 x 10 # Geometry type: LINESTRING # Dimension: XY # Bounding box: xmin: -79.0708 ymin: -2.935125 xmax: -78.91145 ymax: # -2.833441 from to name type lanes oneway sidewalk surface <int> <int> <chr> <chr> <chr> <chr> <chr> <chr> 1 1 2 <NA> resi~ <NA> no <NA> <NA> 2 3 4 <NA> trun~ 1 yes right asphalt 3 5 6 Juan~ resi~ 2 yes both sett # ... with 15,769 more rows, and 2 more variables: # geometry <LINESTRING [°]>, group <int> ``` ] --- count: false #### Demo: Detección de comunidades .left-panel-demo12-user[ ```r net_clean %>% morph(to_linegraph) %>% mutate(group = group_louvain()) %>% unmorph() -> * grouped_net *grouped_net %>% * activate("edges") %>% * pull(group) %>% * unique() %>% * length() ``` ] .right-panel-demo12-user[ ``` [1] 186 ``` ] --- count: false #### Demo: Detección de comunidades .left-panel-demo12-user[ ```r net_clean %>% morph(to_linegraph) %>% mutate(group = group_louvain()) %>% unmorph() -> grouped_net grouped_net %>% activate("edges") %>% pull(group) %>% unique() %>% length() *par(mar = c(0,0,0,0), mfrow = c(1,1)) *plot( * st_geometry(net, "edges"), * col = "grey", lwd = 0.5 *) ``` ] .right-panel-demo12-user[ ``` [1] 186 ``` <img src="slides_files/figure-html/demo12_user_6_output-1.png" width="864" /> ] --- count: false #### Demo: Detección de comunidades .left-panel-demo12-user[ ```r net_clean %>% morph(to_linegraph) %>% mutate(group = group_louvain()) %>% unmorph() -> grouped_net grouped_net %>% activate("edges") %>% pull(group) %>% unique() %>% length() par(mar = c(0,0,0,0), mfrow = c(1,1)) plot( st_geometry(net, "edges"), col = "grey", lwd = 0.5 ) *grouped_net %>% * activate("edges") %>% * st_as_sf() %>% * transmute(group = as.factor(group)) %>% * filter(group %in% c(1:20)) %>% * plot(lwd = 4, add = TRUE) ``` ] .right-panel-demo12-user[ ``` [1] 186 ``` <img src="slides_files/figure-html/demo12_user_7_output-1.png" width="864" /> ] <style> .left-panel-demo12-user { color: #777; width: 38.6138613861386%; height: 92%; float: left; font-size: 80% } .right-panel-demo12-user { width: 59.4059405940594%; float: right; padding-left: 1%; font-size: 80% } .middle-panel-demo12-user { width: 0%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: center, middle ### ¿Quieren más? -- Pueden encontrar documentación y más ejemplos en la [página del paquete](https://luukvdmeer.github.io/sfnetworks/index.html) -- ### ¿Tienen sus propios ejemplos o ideas sobre el paquete? -- Unánse a la [Discusión en GitHub](https://github.com/luukvdmeer/sfnetworks/discussions) -- ### ¿Encontraron un bug? -- Hágannos saber en un [issue aquí](https://github.com/luukvdmeer/sfnetworks/issues)! --- class: center, middle ### ¡Gracias por su atención! #### ¿Preguntas? .note[.pull-left[Proyecto financiado por:<br>] .pull-right[Presentación construida con [xaringan](https://github.com/yihui/xaringan), [xaringanthemer](https://github.com/gadenbuie/xaringanthemer) y [flipbookr](https://github.com/EvaMaeRey/flipbookr)]]