library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.1.2 v dplyr 1.0.6
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ggmap)
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(osrm)
## Data: (c) OpenStreetMap contributors, ODbL 1.0 - http://www.openstreetmap.org/copyright
## Routing: OSRM - http://project-osrm.org/
library(leaflet)
library(sf)
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(Rcpp)
estacionesba <- read_sf("nuevas-estaciones-bicicletas-publicas.geojson", stringsAsFactors = TRUE)
recorridosba <- read.csv("recorridos-realizados-2021.csv", encoding="UTF-8", stringsAsFactors = TRUE)
st_crs(estacionesba)
## Coordinate Reference System:
## User input: WGS 84
## 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]],
## ID["EPSG",4326]]
estacionesba <- st_transform(estacionesba, crs = 4326)
head(recorridosba)
## ID Estado.cerrado Duración Id.de.estación.de.inicio Fecha.de.inicio
## 1 11204995 NORMAL 437 131 2021-06-02 16:14:35
## 2 11204938 NORMAL 406 387 2021-06-02 16:11:01
## 3 11204928 NORMAL 299 232 2021-06-02 16:10:08
## 4 11204920 NORMAL 400 117 2021-06-02 16:09:34
## 5 11204919 NORMAL 591 212 2021-06-02 16:09:32
## 6 11204914 NORMAL 335 161 2021-06-02 16:09:17
## Nombre.de.estación.de.inicio Fecha.de.fin
## 1 131- HOSPITAL DE CLÍNICAS 2021-06-02 16:21:52
## 2 278 - Donato Alvarez 2021-06-02 16:17:47
## 3 252 - Tamborini 2021-06-02 16:15:07
## 4 117 - HUMBERTO 1° 2021-06-02 16:16:14
## 5 129 - Velasco 2021-06-02 16:19:23
## 6 161 - Humahuaca 2021-06-02 16:14:52
## Id.de.estación.de.fin.de.viaje Nombre.de.estación.de.fin.de.viaje
## 1 38 038 - Plaza Libertad
## 2 262 349 - Plaza Saenz Peña
## 3 386 277 - Coghlan
## 4 175 147 - Constitución
## 5 158 158 - VILLARROEL
## 6 121 121 - YATAY
## ID.de.ciclista Tipo.de.ciclista Modelo.de.bicicleta Origen.de.viaje
## 1 119795 MEMBER ICONIC CODE
## 2 348428 MEMBER ICONIC CODE
## 3 690073 MEMBER ICONIC CODE
## 4 713938 MEMBER ICONIC CODE
## 5 35926 MEMBER ICONIC CODE
## 6 536195 MEMBER ICONIC CODE
head(estacionesba)
## Simple feature collection with 6 features and 7 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -58.42095 ymin: -34.62853 xmax: -58.36826 ymax: -34.58055
## Geodetic CRS: WGS 84
## # A tibble: 6 x 8
## id codigo nombre ubicacion tipo horario anclajes_t
## <int> <int> <fct> <fct> <fct> <fct> <int>
## 1 2 2 002 - Ret~ Ramos Mejia, Jose ~ AUTOM~ Estación automá~ 20
## 2 3 3 003 - ADU~ Moreno & Av Paseo ~ AUTOM~ Estación automá~ 20
## 3 4 4 004 - Pla~ Lavalle & Bouchard AUTOM~ Estación automá~ 20
## 4 5 5 005 - Pla~ Av. Sarmiento 2601 AUTOM~ Estación automá~ 42
## 5 6 6 006 - Par~ Avenida Martin Gar~ AUTOM~ Estación automá~ 20
## 6 7 7 007 - OBE~ CARLOS PELEGRINI 2~ AUTOM~ Estación automá~ 16
## # ... with 1 more variable: geometry <POINT [°]>
estacionesba <- estacionesba %>%
mutate(lat = unlist(map(estacionesba$geometry,1)),
long = unlist(map(estacionesba$geometry,2)))
head(estacionesba,700)
## Simple feature collection with 229 features and 9 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -58.51142 ymin: -34.66051 xmax: -58.35574 ymax: -34.5445
## Geodetic CRS: WGS 84
## # A tibble: 229 x 10
## id codigo nombre ubicacion tipo horario anclajes_t
## <int> <int> <fct> <fct> <fct> <fct> <int>
## 1 2 2 002 - Reti~ Ramos Mejia, Jose~ AUTOM~ Estación autom~ 20
## 2 3 3 003 - ADUA~ Moreno & Av Paseo~ AUTOM~ Estación autom~ 20
## 3 4 4 004 - Plaz~ Lavalle & Bouchard AUTOM~ Estación autom~ 20
## 4 5 5 005 - Plaz~ Av. Sarmiento 2601 AUTOM~ Estación autom~ 42
## 5 6 6 006 - Parq~ Avenida Martin Ga~ AUTOM~ Estación autom~ 20
## 6 7 7 007 - OBEL~ CARLOS PELEGRINI ~ AUTOM~ Estación autom~ 16
## 7 8 8 008 - Cong~ Cevallos, Virrey&~ AUTOM~ Estación autom~ 24
## 8 9 9 009 - Parq~ 2300 Diaz, Cnel. ~ AUTOM~ Estación autom~ 24
## 9 11 12 012 - Plaz~ Parana & Juncal AUTOM~ Estación autom~ 16
## 10 12 13 013 - ONCE Av. Pueyrredon & ~ AUTOM~ Estación autom~ 30
## # ... with 219 more rows, and 3 more variables: geometry <POINT [°]>,
## # lat <dbl>, long <dbl>
bbox_estaciones <- make_bbox(estacionesba$lat, estacionesba$long)
mapa_estaciones <- get_stamenmap(bbox_estaciones,
zoom = 12)
## Source : http://tile.stamen.com/terrain/12/1382/2467.png
## Source : http://tile.stamen.com/terrain/12/1383/2467.png
## Source : http://tile.stamen.com/terrain/12/1384/2467.png
## Source : http://tile.stamen.com/terrain/12/1382/2468.png
## Source : http://tile.stamen.com/terrain/12/1383/2468.png
## Source : http://tile.stamen.com/terrain/12/1384/2468.png
ggmap(mapa_estaciones)
head(recorridosba,15)
## ID Estado.cerrado Duración Id.de.estación.de.inicio
## 1 11204995 NORMAL 437 131
## 2 11204938 NORMAL 406 387
## 3 11204928 NORMAL 299 232
## 4 11204920 NORMAL 400 117
## 5 11204919 NORMAL 591 212
## 6 11204914 NORMAL 335 161
## 7 11204912 NORMAL 215 179
## 8 11204909 NORMAL 659 261
## 9 11204906 NORMAL 673 190
## 10 11204904 NORMAL 485 65
## 11 11204903 NORMAL 573 82
## 12 11204899 NORMAL 687 359
## 13 11204898 NORMAL 548 64
## 14 11204896 NORMAL 471 121
## 15 11204887 NORMAL 571 425
## Fecha.de.inicio Nombre.de.estación.de.inicio Fecha.de.fin
## 1 2021-06-02 16:14:35 131- HOSPITAL DE CLÍNICAS 2021-06-02 16:21:52
## 2 2021-06-02 16:11:01 278 - Donato Alvarez 2021-06-02 16:17:47
## 3 2021-06-02 16:10:08 252 - Tamborini 2021-06-02 16:15:07
## 4 2021-06-02 16:09:34 117 - HUMBERTO 1° 2021-06-02 16:16:14
## 5 2021-06-02 16:09:32 129 - Velasco 2021-06-02 16:19:23
## 6 2021-06-02 16:09:17 161 - Humahuaca 2021-06-02 16:14:52
## 7 2021-06-02 16:09:05 179 - CASA SAN 2021-06-02 16:12:40
## 8 2021-06-02 16:08:48 272 - Plaza Bruno Giordano 2021-06-02 16:19:47
## 9 2021-06-02 16:08:37 190 - JUNCAL 2021-06-02 16:19:50
## 10 2021-06-02 16:08:29 065 - Julián Álvarez 2021-06-02 16:16:34
## 11 2021-06-02 16:08:28 082 - HOSPITAL ITALIANO 2021-06-02 16:18:01
## 12 2021-06-02 16:08:20 250 - Fleni 2021-06-02 16:19:47
## 13 2021-06-02 16:08:05 064 - RIOBAMBA 2021-06-02 16:17:13
## 14 2021-06-02 16:07:50 121 - YATAY 2021-06-02 16:15:41
## 15 2021-06-02 16:07:28 394 - Av. La Plata 2021-06-02 16:16:59
## Id.de.estación.de.fin.de.viaje Nombre.de.estación.de.fin.de.viaje
## 1 38 038 - Plaza Libertad
## 2 262 349 - Plaza Saenz Peña
## 3 386 277 - Coghlan
## 4 175 147 - Constitución
## 5 158 158 - VILLARROEL
## 6 121 121 - YATAY
## 7 126 126 - Ministerio de Justicia y Seguridad
## 8 316 205 - SAN MARTIN
## 9 54 054 - Acuña de Figueroa
## 10 200 200 - AUSTRIA Y FRENCH
## 11 25 025 - Plaza Guemes
## 12 230 259 - PLAZA CASTELLI
## 13 200 200 - AUSTRIA Y FRENCH
## 14 54 054 - Acuña de Figueroa
## 15 41 041 - Urquiza y Rondeau
## ID.de.ciclista Tipo.de.ciclista Modelo.de.bicicleta Origen.de.viaje
## 1 119795 MEMBER ICONIC CODE
## 2 348428 MEMBER ICONIC CODE
## 3 690073 MEMBER ICONIC CODE
## 4 713938 MEMBER ICONIC CODE
## 5 35926 MEMBER ICONIC CODE
## 6 536195 MEMBER ICONIC CODE
## 7 741035 MEMBER ICONIC CODE
## 8 183435 MEMBER ICONIC CODE
## 9 55881 MEMBER ICONIC CODE
## 10 12438 MEMBER ICONIC CODE
## 11 674975 MEMBER ICONIC CODE
## 12 770532 MEMBER ICONIC CODE
## 13 569922 MEMBER ICONIC CODE
## 14 684421 MEMBER ICONIC CODE
## 15 275651 MEMBER ICONIC CODE
toprecorridos <- recorridosba %>%
group_by(Id.de.estación.de.inicio, Nombre.de.estación.de.inicio, Id.de.estación.de.fin.de.viaje, Nombre.de.estación.de.fin.de.viaje) %>%
summarise(cant_viajes = n())
## `summarise()` has grouped output by 'Id.de.estación.de.inicio', 'Nombre.de.estación.de.inicio', 'Id.de.estación.de.fin.de.viaje'. You can override using the `.groups` argument.
toprecorridos %>%
arrange(desc(cant_viajes)) %>%
head(20)
## # A tibble: 20 x 5
## # Groups: Id.de.estación.de.inicio, Nombre.de.estación.de.inicio,
## # Id.de.estación.de.fin.de.viaje [20]
## Id.de.estación.de~ Nombre.de.estación~ Id.de.estación.de~ Nombre.de.estación~
## <int> <fct> <dbl> <fct>
## 1 152 152 - JULIETA LANT~ 152 152 - JULIETA LANT~
## 2 268 399 - GARCIA DEL R~ 268 399 - GARCIA DEL R~
## 3 222 160 - Godoy Cruz y~ 222 160 - Godoy Cruz y~
## 4 277 292 - PLAZA BOLIVIA 277 292 - PLAZA BOLIVIA
## 5 29 029 - Parque Cente~ 29 029 - Parque Cente~
## 6 210 335 - General Urqu~ 210 335 - General Urqu~
## 7 5 005 - Plaza Italia 5 005 - Plaza Italia
## 8 14 014 - Pacifico 14 014 - Pacifico
## 9 289 255 - BARRANCAS DE~ 289 255 - BARRANCAS DE~
## 10 281 350 - Plaza Irlanda 281 350 - Plaza Irlanda
## 11 335 206 - Galicia 449 352 - San Jose de ~
## 12 202 001 - FACULTAD DE ~ 202 001 - FACULTAD DE ~
## 13 449 352 - San Jose de ~ 335 206 - Galicia
## 14 8 008 - Congreso 8 008 - Congreso
## 15 74 074 - INSTITUTO L~ 74 074 - INSTITUTO L~
## 16 151 151 - AIME PAINÉ 151 151 - AIME PAINÉ
## 17 14 014 - Pacifico 239 391 - Plaza Repúbl~
## 18 21 021 - Parque Patri~ 21 021 - Parque Patri~
## 19 239 391 - Plaza Repúbl~ 239 391 - Plaza Repúbl~
## 20 239 391 - Plaza Repúbl~ 14 014 - Pacifico
## # ... with 1 more variable: cant_viajes <int>
ggplot() +
geom_tile(data = toprecorridos, aes(x = as.factor(Id.de.estación.de.inicio), y = as.factor(Id.de.estación.de.fin.de.viaje), fill = cant_viajes)) +
scale_fill_distiller(palette = "RdYlGn")+
labs(title="Matriz Origen-Destino")
Elaborando un ranking con los 10 recorridos mas frecuentados, podemos observar que, llamativamente, el top esta en su totalidad conformado por viajes que comienzan y terminan en la misma estación. Ampliando el ranking a los 20 recorridos principales, observamos que recién en el decimo primer puesto aparece un trayecto con cabeceras distintas. En función de estos datos puede inferirse que las bicicletas tienen un uso mayormente recreativo o bien se emplean en trayectos netamente de cercanía. Esto último surge de la limitación de tiempo de uso de hasta 30 minutos. En la matriz orígen destino, se pueden identificar que aquellos trayectos con mayor cantidad de repeticiones (mas de 1000) se encuentran en la línea central con mismo orígen-destino, respaldando lo ya mencionado.
Identificamos, entonces, los 10 recorridos mas frecuentados con orígen-destino distinto.
toprecorridos2 <- toprecorridos %>%
filter(Id.de.estación.de.inicio != Id.de.estación.de.fin.de.viaje) %>%
arrange(desc(cant_viajes)) %>%
head(20)
head(toprecorridos2,20)
## # A tibble: 20 x 5
## # Groups: Id.de.estación.de.inicio, Nombre.de.estación.de.inicio,
## # Id.de.estación.de.fin.de.viaje [20]
## Id.de.estación.de~ Nombre.de.estación~ Id.de.estación.de~ Nombre.de.estación~
## <int> <fct> <dbl> <fct>
## 1 335 206 - Galicia 449 352 - San Jose de ~
## 2 449 352 - San Jose de ~ 335 206 - Galicia
## 3 14 014 - Pacifico 239 391 - Plaza Repúbl~
## 4 239 391 - Plaza Repúbl~ 14 014 - Pacifico
## 5 277 292 - PLAZA BOLIVIA 289 255 - BARRANCAS DE~
## 6 289 255 - BARRANCAS DE~ 277 292 - PLAZA BOLIVIA
## 7 14 014 - Pacifico 222 160 - Godoy Cruz y~
## 8 5 005 - Plaza Italia 210 335 - General Urqu~
## 9 5 005 - Plaza Italia 222 160 - Godoy Cruz y~
## 10 448 393 - Barrio 31 130 130 - RETIRO II
## 11 202 001 - FACULTAD DE ~ 242 103 - MALBA
## 12 14 014 - Pacifico 364 381 - Matienzo Y A~
## 13 29 029 - Parque Cente~ 17 017 - Plaza Almagro
## 14 278 233 - MONROE 268 399 - GARCIA DEL R~
## 15 268 399 - GARCIA DEL R~ 416 257 - Plaza Franci~
## 16 17 017 - Plaza Almagro 29 029 - Parque Cente~
## 17 277 292 - PLAZA BOLIVIA 14 014 - Pacifico
## 18 277 292 - PLAZA BOLIVIA 222 160 - Godoy Cruz y~
## 19 5 005 - Plaza Italia 44 044 - Ecoparque
## 20 416 257 - Plaza Franci~ 268 399 - GARCIA DEL R~
## # ... with 1 more variable: cant_viajes <int>
Podemos observar que los primeros resultados se tratan de trayectos de ida y vuelta entre estaciones, mientras que otros casos como Plaza Italia o Pacífico, se trata de viajes originados en un centro de transbordo de importancia.
toprecorridos2 <- toprecorridos2 %>%
left_join(estacionesba, by=c("Nombre.de.estación.de.inicio"="nombre"))
toprecorridos2 <- toprecorridos2 %>%
rename(lat_inicio=lat,
long_inicio=long)
head(toprecorridos2,20)
## # A tibble: 20 x 14
## # Groups: Id.de.estación.de.inicio, Nombre.de.estación.de.inicio,
## # Id.de.estación.de.fin.de.viaje [20]
## Id.de.estación.de~ Nombre.de.estación~ Id.de.estación.de~ Nombre.de.estación~
## <int> <fct> <dbl> <fct>
## 1 335 206 - Galicia 449 352 - San Jose de ~
## 2 449 352 - San Jose de ~ 335 206 - Galicia
## 3 14 014 - Pacifico 239 391 - Plaza Repúbl~
## 4 239 391 - Plaza Repúbl~ 14 014 - Pacifico
## 5 277 292 - PLAZA BOLIVIA 289 255 - BARRANCAS DE~
## 6 289 255 - BARRANCAS DE~ 277 292 - PLAZA BOLIVIA
## 7 14 014 - Pacifico 222 160 - Godoy Cruz y~
## 8 5 005 - Plaza Italia 210 335 - General Urqu~
## 9 5 005 - Plaza Italia 222 160 - Godoy Cruz y~
## 10 448 393 - Barrio 31 130 130 - RETIRO II
## 11 202 001 - FACULTAD DE ~ 242 103 - MALBA
## 12 14 014 - Pacifico 364 381 - Matienzo Y A~
## 13 29 029 - Parque Cente~ 17 017 - Plaza Almagro
## 14 278 233 - MONROE 268 399 - GARCIA DEL R~
## 15 268 399 - GARCIA DEL R~ 416 257 - Plaza Franci~
## 16 17 017 - Plaza Almagro 29 029 - Parque Cente~
## 17 277 292 - PLAZA BOLIVIA 14 014 - Pacifico
## 18 277 292 - PLAZA BOLIVIA 222 160 - Godoy Cruz y~
## 19 5 005 - Plaza Italia 44 044 - Ecoparque
## 20 416 257 - Plaza Franci~ 268 399 - GARCIA DEL R~
## # ... with 10 more variables: cant_viajes <int>, id <int>, codigo <int>,
## # ubicacion <fct>, tipo <fct>, horario <fct>, anclajes_t <int>,
## # geometry <POINT [°]>, lat_inicio <dbl>, long_inicio <dbl>
toprecorridos2 <- toprecorridos2 %>%
left_join(estacionesba, by=c("Nombre.de.estación.de.fin.de.viaje"="nombre"))
toprecorridos2 <- toprecorridos2 %>%
rename(lat_fin=lat,
long_fin=long)
head(toprecorridos2,20)
## # A tibble: 20 x 23
## # Groups: Id.de.estación.de.inicio, Nombre.de.estación.de.inicio,
## # Id.de.estación.de.fin.de.viaje [20]
## Id.de.estación.de~ Nombre.de.estación~ Id.de.estación.de~ Nombre.de.estación~
## <int> <fct> <dbl> <fct>
## 1 335 206 - Galicia 449 352 - San Jose de ~
## 2 449 352 - San Jose de ~ 335 206 - Galicia
## 3 14 014 - Pacifico 239 391 - Plaza Repúbl~
## 4 239 391 - Plaza Repúbl~ 14 014 - Pacifico
## 5 277 292 - PLAZA BOLIVIA 289 255 - BARRANCAS DE~
## 6 289 255 - BARRANCAS DE~ 277 292 - PLAZA BOLIVIA
## 7 14 014 - Pacifico 222 160 - Godoy Cruz y~
## 8 5 005 - Plaza Italia 210 335 - General Urqu~
## 9 5 005 - Plaza Italia 222 160 - Godoy Cruz y~
## 10 448 393 - Barrio 31 130 130 - RETIRO II
## 11 202 001 - FACULTAD DE ~ 242 103 - MALBA
## 12 14 014 - Pacifico 364 381 - Matienzo Y A~
## 13 29 029 - Parque Cente~ 17 017 - Plaza Almagro
## 14 278 233 - MONROE 268 399 - GARCIA DEL R~
## 15 268 399 - GARCIA DEL R~ 416 257 - Plaza Franci~
## 16 17 017 - Plaza Almagro 29 029 - Parque Cente~
## 17 277 292 - PLAZA BOLIVIA 14 014 - Pacifico
## 18 277 292 - PLAZA BOLIVIA 222 160 - Godoy Cruz y~
## 19 5 005 - Plaza Italia 44 044 - Ecoparque
## 20 416 257 - Plaza Franci~ 268 399 - GARCIA DEL R~
## # ... with 19 more variables: cant_viajes <int>, id.x <int>, codigo.x <int>,
## # ubicacion.x <fct>, tipo.x <fct>, horario.x <fct>, anclajes_t.x <int>,
## # geometry.x <POINT [°]>, lat_inicio <dbl>, long_inicio <dbl>, id.y <int>,
## # codigo.y <int>, ubicacion.y <fct>, tipo.y <fct>, horario.y <fct>,
## # anclajes_t.y <int>, geometry.y <POINT [°]>, lat_fin <dbl>, long_fin <dbl>
ruteo_recorridos <- function(Nombre.de.estación.de.inicio, lat_inicio, long_inicio,
Nombre.de.estación.de.fin.de.viaje, lat_fin, long_fin) {
ruta <- osrmRoute(src = c(Nombre.de.estación.de.inicio, lat_inicio, long_inicio),
dst = c(Nombre.de.estación.de.fin.de.viaje, lat_fin, long_fin),
returnclass = "sf",
overview = "full",
osrm.profile = "bike")
cbind(Nombre.de.estación.de.inicio, Nombre.de.estación.de.fin.de.viaje, ruta)
}
ruteo_ba <- list(toprecorridos2$Nombre.de.estación.de.inicio, toprecorridos2$lat_inicio, toprecorridos2$long_inicio,
toprecorridos2$Nombre.de.estación.de.fin.de.viaje, toprecorridos2$lat_fin, toprecorridos2$long_fin)
ruteo_toprecorridos <- pmap(ruteo_ba, ruteo_recorridos) %>%
reduce(rbind)
ggmap(mapa_estaciones)+
geom_sf(data=ruteo_toprecorridos, color="red", size=1.5, inherit.aes = FALSE)+
labs(title="Top 20 Recorridos más Realizados en Bicicleta",
subtitle="Buenos Aires, Argentina",
caption="Fuente: BA Data")+
scale_color_viridis_c(direction=-1)+
theme_void()
## Coordinate system already present. Adding new coordinate system, which will replace the existing one.