TP 5

Analizando y visualizando flujos de viajes urbanos

Fecha de entrega: 24 de mayo

library(tidyverse)
## -- Attaching packages -------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.0     v purrr   0.3.3
## v tibble  2.1.3     v dplyr   0.8.4
## v tidyr   1.0.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## -- 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.6.1, GDAL 2.2.3, PROJ 4.9.3

I. Elegir un dataset que contenga viajes origen-destino (por ejemplo bicicletas públicas) de la Ciudad con la que están trabajando.

Descargamos el dataset con la información de las estacciones de bicicleta “Citi Bike NYC”:

viajes_bici_nyc <- read_csv("202003-citibike-tripdata.csv")
## Parsed with column specification:
## cols(
##   tripduration = col_double(),
##   starttime = col_datetime(format = ""),
##   stoptime = col_datetime(format = ""),
##   `start station id` = col_double(),
##   `start station name` = col_character(),
##   `start station latitude` = col_double(),
##   `start station longitude` = col_double(),
##   `end station id` = col_double(),
##   `end station name` = col_character(),
##   `end station latitude` = col_double(),
##   `end station longitude` = col_double(),
##   bikeid = col_double(),
##   usertype = col_character(),
##   `birth year` = col_double(),
##   gender = col_double()
## )
viajes_bici_nyc
## # A tibble: 1,068,457 x 15
##    tripduration starttime           stoptime            `start station ~
##           <dbl> <dttm>              <dttm>                         <dbl>
##  1         1589 2020-03-01 00:00:03 2020-03-01 00:26:32              224
##  2          389 2020-03-01 00:00:16 2020-03-01 00:06:46              293
##  3          614 2020-03-01 00:00:20 2020-03-01 00:10:34              379
##  4          597 2020-03-01 00:00:24 2020-03-01 00:10:22             3739
##  5         1920 2020-03-01 00:00:26 2020-03-01 00:32:26              236
##  6         2055 2020-03-01 00:00:46 2020-03-01 00:35:01              471
##  7          764 2020-03-01 00:01:04 2020-03-01 00:13:49               83
##  8         1719 2020-03-01 00:01:04 2020-03-01 00:29:44             3809
##  9          441 2020-03-01 00:01:09 2020-03-01 00:08:30             3463
## 10          601 2020-03-01 00:01:09 2020-03-01 00:11:11              406
## # ... with 1,068,447 more rows, and 11 more variables: `start station
## #   name` <chr>, `start station latitude` <dbl>, `start station
## #   longitude` <dbl>, `end station id` <dbl>, `end station name` <chr>, `end
## #   station latitude` <dbl>, `end station longitude` <dbl>, bikeid <dbl>,
## #   usertype <chr>, `birth year` <dbl>, gender <dbl>
names(viajes_bici_nyc)
##  [1] "tripduration"            "starttime"              
##  [3] "stoptime"                "start station id"       
##  [5] "start station name"      "start station latitude" 
##  [7] "start station longitude" "end station id"         
##  [9] "end station name"        "end station latitude"   
## [11] "end station longitude"   "bikeid"                 
## [13] "usertype"                "birth year"             
## [15] "gender"
names(viajes_bici_nyc) <- gsub(" ", "_", names(viajes_bici_nyc))
names(viajes_bici_nyc)
##  [1] "tripduration"            "starttime"              
##  [3] "stoptime"                "start_station_id"       
##  [5] "start_station_name"      "start_station_latitude" 
##  [7] "start_station_longitude" "end_station_id"         
##  [9] "end_station_name"        "end_station_latitude"   
## [11] "end_station_longitude"   "bikeid"                 
## [13] "usertype"                "birth_year"             
## [15] "gender"

Generamos la bbox a partir de la información del dataset:

bbox <- make_bbox(viajes_bici_nyc$start_station_longitude, viajes_bici_nyc$start_station_latitude)

bbox
##      left    bottom     right       top 
## -74.02309  40.64725 -73.89199  40.82644
mapa_base <- get_stamenmap(bbox, color = "bw", zoom = 12, maptype = "terrain")
## Source : http://tile.stamen.com/terrain/12/1205/1538.png
## Source : http://tile.stamen.com/terrain/12/1206/1538.png
## Source : http://tile.stamen.com/terrain/12/1207/1538.png
## Source : http://tile.stamen.com/terrain/12/1205/1539.png
## Source : http://tile.stamen.com/terrain/12/1206/1539.png
## Source : http://tile.stamen.com/terrain/12/1207/1539.png
## Source : http://tile.stamen.com/terrain/12/1205/1540.png
## Source : http://tile.stamen.com/terrain/12/1206/1540.png
## Source : http://tile.stamen.com/terrain/12/1207/1540.png
## Source : http://tile.stamen.com/terrain/12/1205/1541.png
## Source : http://tile.stamen.com/terrain/12/1206/1541.png
## Source : http://tile.stamen.com/terrain/12/1207/1541.png
ggmap(mapa_base)