library(tidyverse)
## -- Attaching packages --------------------------------------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.2.0 v purrr 0.3.2
## v tibble 2.1.1 v dplyr 0.8.1
## v tidyr 0.8.3 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## -- Conflicts ------------------------------------------------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(lubridate)
## Warning: package 'lubridate' was built under R version 3.6.1
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
viajes <- read_csv("https://bitsandbricks.github.io/data/viajes_BA_bici_abril_2017.csv")
## Parsed with column specification:
## cols(
## HORA = col_datetime(format = ""),
## ORIGEN_ESTACION = col_double(),
## NOMBRE_ORIGEN = col_character(),
## DESTINO_ESTACION = col_double(),
## NOMBRE_DESTINO = col_character(),
## TOTAL = col_double()
## )
viajes
## # A tibble: 113,650 x 6
## HORA ORIGEN_ESTACION NOMBRE_ORIGEN DESTINO_ESTACION
## <dttm> <dbl> <chr> <dbl>
## 1 2017-04-01 00:00:00 1 FACULTAD DE ~ 42
## 2 2017-04-01 00:00:00 5 PLAZA ITALIA 14
## 3 2017-04-01 00:00:00 5 PLAZA ITALIA 20
## 4 2017-04-01 00:00:00 5 PLAZA ITALIA 69
## 5 2017-04-01 00:00:00 5 PLAZA ITALIA 94
## 6 2017-04-01 00:00:00 5 PLAZA ITALIA 123
## 7 2017-04-01 00:00:00 6 PARQUE LEZAMA 17
## 8 2017-04-01 00:00:00 6 PARQUE LEZAMA 28
## 9 2017-04-01 00:00:00 6 PARQUE LEZAMA 118
## 10 2017-04-01 00:00:00 8 CONGRESO 1
## # ... with 113,640 more rows, and 2 more variables: NOMBRE_DESTINO <chr>,
## # TOTAL <dbl>
estaciones5 <- read.csv("https://bitsandbricks.github.io/data/estaciones_BA_bici.csv")
library(ggmap)
## Warning: package 'ggmap' was built under R version 3.6.1
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
bbox <- make_bbox(estaciones5$X, estaciones5$Y)
bbox
## left bottom right top
## -58.46000 -34.64541 -58.35132 -34.56439
mapa_base <- get_stamenmap(bbox, color = "bw", 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_base) +
geom_point(data = estaciones5, aes(x = X, y = Y), color = "limegreen", size = 2) +
theme_nothing()
conteoViajes <- viajes %>%
group_by(ORIGEN_ESTACION, DESTINO_ESTACION) %>%
summarise(total = sum(TOTAL))
ggplot() +
geom_tile(data = conteoViajes,
aes(x = as.factor(ORIGEN_ESTACION),
y = as.factor(DESTINO_ESTACION),
fill = total)) +
scale_fill_distiller(palette = "Spectral")
Descarto viajes circulares
top10 <- conteoViajes %>%
ungroup() %>%
filter(ORIGEN_ESTACION != DESTINO_ESTACION) %>%
top_n(10)
## Selecting by total
top10
## # A tibble: 10 x 3
## ORIGEN_ESTACION DESTINO_ESTACION total
## <dbl> <dbl> <dbl>
## 1 1 2 333
## 2 1 44 146
## 3 2 1 311
## 4 2 10 181
## 5 2 164 115
## 6 9 44 121
## 7 10 2 182
## 8 30 9 118
## 9 44 1 176
## 10 44 14 127
ggplot() +
geom_tile(data = top10,
aes(x = as.factor(ORIGEN_ESTACION),
y = as.factor(DESTINO_ESTACION),
fill = total)) +
scale_fill_distiller(palette = "Spectral")
Estaciones 1 y 2 son las más frecuentes
library(osrm)
## Warning: package 'osrm' was built under R version 3.6.1
## Data: (c) OpenStreetMap contributors, ODbL 1.0 - http://www.openstreetmap.org/copyright
## Routing: OSRM - http://project-osrm.org/
58.39245 -34.58313 FACULTAD DE DERECHO 1 -58.37482 -34.59259 RETIRO 2 -58.41459 -34.57549 ZOOLOGICO AV DEL LIBERTADOR Y AV SARMIENTO 44 -58.36575 -34.61555 PUERTO MADERO - UCA
top10 <- top10 %>%
left_join(estaciones5[c("X", "Y", "NOMBRE", "NRO_EST")],
by = c("ORIGEN_ESTACION" = "NRO_EST")) %>%
rename(ORIGEN_X = X,
ORIGEN_Y = Y,
ORIGEN_NOMBRE = NOMBRE)
top10
## # A tibble: 10 x 6
## ORIGEN_ESTACION DESTINO_ESTACION total ORIGEN_X ORIGEN_Y ORIGEN_NOMBRE
## <dbl> <dbl> <dbl> <dbl> <dbl> <fct>
## 1 1 2 333 -58.4 -34.6 FACULTAD DE DE~
## 2 1 44 146 -58.4 -34.6 FACULTAD DE DE~
## 3 2 1 311 -58.4 -34.6 RETIRO
## 4 2 10 181 -58.4 -34.6 RETIRO
## 5 2 164 115 -58.4 -34.6 RETIRO
## 6 9 44 121 -58.4 -34.6 PARQUE LAS HER~
## 7 10 2 182 -58.4 -34.6 PUERTO MADERO ~
## 8 30 9 118 -58.4 -34.6 PEÑA
## 9 44 1 176 -58.4 -34.6 ZOOLOGICO
## 10 44 14 127 -58.4 -34.6 ZOOLOGICO
top10 <- top10 %>%
left_join(estaciones5[c("X", "Y", "NOMBRE", "NRO_EST")],
by = c("DESTINO_ESTACION" = "NRO_EST")) %>%
rename(DESTINO_X = X,
DESTINO_Y = Y,
DESTINO_NOMBRE = NOMBRE)
top10
## # A tibble: 10 x 9
## ORIGEN_ESTACION DESTINO_ESTACION total ORIGEN_X ORIGEN_Y ORIGEN_NOMBRE
## <dbl> <dbl> <dbl> <dbl> <dbl> <fct>
## 1 1 2 333 -58.4 -34.6 FACULTAD DE ~
## 2 1 44 146 -58.4 -34.6 FACULTAD DE ~
## 3 2 1 311 -58.4 -34.6 RETIRO
## 4 2 10 181 -58.4 -34.6 RETIRO
## 5 2 164 115 -58.4 -34.6 RETIRO
## 6 9 44 121 -58.4 -34.6 PARQUE LAS H~
## 7 10 2 182 -58.4 -34.6 PUERTO MADER~
## 8 30 9 118 -58.4 -34.6 PEÑA
## 9 44 1 176 -58.4 -34.6 ZOOLOGICO
## 10 44 14 127 -58.4 -34.6 ZOOLOGICO
## # ... with 3 more variables: DESTINO_X <dbl>, DESTINO_Y <dbl>,
## # DESTINO_NOMBRE <fct>
recorridos <- read_csv("https://bitsandbricks.github.io/data/recorridos_BA_bici.csv")
## Parsed with column specification:
## cols(
## ORIGEN_ESTACION = col_double(),
## DESTINO_ESTACION = col_double(),
## lon = col_double(),
## lat = col_double(),
## total = col_double()
## )
recorridos
## # A tibble: 149 x 5
## ORIGEN_ESTACION DESTINO_ESTACION lon lat total
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 2 -58.4 -34.6 174
## 2 1 2 -58.4 -34.6 174
## 3 1 2 -58.4 -34.6 174
## 4 1 2 -58.4 -34.6 174
## 5 1 2 -58.4 -34.6 174
## 6 1 2 -58.4 -34.6 174
## 7 1 2 -58.4 -34.6 174
## 8 1 2 -58.4 -34.6 174
## 9 1 2 -58.4 -34.6 174
## 10 1 2 -58.4 -34.6 174
## # ... with 139 more rows
recorridos <- recorridos %>%
mutate(ID = paste(ORIGEN_ESTACION, "-", DESTINO_ESTACION))
ggmap(mapa_base) +
geom_path(data = recorridos, aes(x = lon, y = lat, color = ID, size = total), alpha = 0.7) +
theme_nothing()