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
bici19_cdn <- read.csv("bici19.csv", encoding = "UTF-8" )
summary(bici19_cdn)
##  bici_id_usuario          bici_Fecha_hora_retiro bici_tiempo_uso 
##  Min.   :    33   2019-01-07 20:13:12:     4     Min.   :  0.00  
##  1st Qu.:177438   2019-01-11 14:58:09:     4     1st Qu.:  8.00  
##  Median :375196   2019-01-14 12:50:25:     4     Median : 14.00  
##  Mean   :359739   2019-01-16 15:54:47:     4     Mean   : 16.51  
##  3rd Qu.:547898   2019-01-17 14:16:34:     4     3rd Qu.: 21.00  
##  Max.   :693680   2019-01-25 08:21:43:     4     Max.   :118.00  
##                   (Other)            :204083     NA's   :131     
##           bici_nombre_estacion_origen bici_estacion_origen
##  Vera Peñaloza          :  3092       Min.   :  1.0       
##  Facultad de Medicina   :  3046       1st Qu.: 54.0       
##  Independencia          :  2902       Median : 98.0       
##  Lima                   :  2781       Mean   :100.5       
##  Godoy Cruz y Libertador:  2600       3rd Qu.:149.0       
##  Don Bosco              :  2526       Max.   :600.0       
##  (Other)                :187160                           
##        bici_nombre_estacion_destino bici_estacion_destino
##  Vera Peñaloza       :  3091        Min.   :  1.0        
##  Facultad de Medicina:  3040        1st Qu.: 55.0        
##  Independencia       :  2698        Median : 99.0        
##  Lima                :  2663        Mean   :101.2        
##  Saavedra            :  2600        3rd Qu.:149.0        
##  Don Bosco           :  2523        Max.   :600.0        
##  (Other)             :187492        NA's   :131          
##         bici_sexo        bici_edad    
##  FEMENINO    : 54268   Min.   :16.00  
##  MASCULINO   :149804   1st Qu.:25.00  
##  NO INFORMADO:    35   Median :30.00  
##                        Mean   :33.26  
##                        3rd Qu.:39.00  
##                        Max.   :87.00  
## 
bicisCABA <- bici19_cdn %>% mutate (bici_Fecha_hora_retiro = ymd_hms(bici_Fecha_hora_retiro))
set.seed("99")
muestra_de_fechas <- bicisCABA %>% 
    sample_n(5) %>% 
    pull(bici_Fecha_hora_retiro)
muestra_de_fechas
## [1] "2019-01-01 01:46:58 UTC" "2019-01-18 09:30:57 UTC"
## [3] "2019-01-13 15:45:12 UTC" "2019-01-31 17:06:52 UTC"
## [5] "2019-01-16 14:07:01 UTC"
options(scipen = 20)

ggplot(bicisCABA) + 
    geom_bar(aes(x = hour(bici_Fecha_hora_retiro)))

La muestra registra que durante la mañana el pico de uso es 8 am, desciende al mediodía y comienza a subir hasta el nuevo pico 6 pm.

bicisCABA %>% 
    ggplot() +
        geom_bar(aes(x = day(bici_Fecha_hora_retiro)))

Los resultados no permiten comparar entre días pico de todo el año, ya que el dataset tiene registros de unos pocos menes en el 2019.

Analizando la distribución de datos:

bicisCABA %>% 
    count(bici_nombre_estacion_origen) %>% 
    top_n(5) %>% 
    arrange(desc(n))
## Selecting by n
## # A tibble: 5 x 2
##   bici_nombre_estacion_origen     n
##   <fct>                       <int>
## 1 Vera Peñaloza                3092
## 2 Facultad de Medicina         3046
## 3 Independencia                2902
## 4 Lima                         2781
## 5 Godoy Cruz y Libertador      2600
estacionesfrecuentes <- bicisCABA %>% 
    count(bici_nombre_estacion_origen) %>% 
    top_n(5) %>% 
    pull(bici_nombre_estacion_origen)
## Selecting by n
bicisCABA %>% 
    filter(year(bici_Fecha_hora_retiro) == 2019,
           bici_nombre_estacion_origen %in% estacionesfrecuentes) %>% 
    ggplot() +
        geom_bar(aes(x = month(bici_Fecha_hora_retiro, label = TRUE), fill = bici_nombre_estacion_origen))

bicisCABA %>% 
    filter(year(bici_Fecha_hora_retiro) == 2019,
           bici_nombre_estacion_origen %in% estacionesfrecuentes) %>% 
    ggplot() +
        geom_bar(aes(x = month(bici_Fecha_hora_retiro, label = TRUE), fill =bici_nombre_estacion_origen),
                 position = "dodge")

acá hay algo mal porque me raba el knit( el error que me aparece es Error in useMethod(“filter_”)

conteo_ <- estacionesfrecuentes %>% filter(year(bici_Fecha_hora_retiro) == 2019, bici_nombre_estacion_origen %in% estacionesfrecuentes) %>% count(bici_nombre_estacion_origen, mes = month(bici_Fecha_hora_retiro, label = TRUE))

ggplot(conteo_) + geom_line(aes(x = mes, y = n, group = bici_nombre_estacion_origen, color = bici_nombre_estacion_origen))

por_hora <- estacionesfrecuentes %>% filter(year(bici_Fecha_hora_retiro) == 2019, bici_nombre_estacion_origen %in% estacionesfrecuentes) %>% count(bici_nombre_estacion_origen, diasemana = wday(bici_nombre_estacion_origen, label = TRUE )) ggplot(conteo_) + geom_line(aes(x = diasemana, y = n, group = bici_nombre_estacion_origen, color = tipo_delito))

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.
estaciones <- read.csv("estaciones_bici_geo.csv", encoding = "UTF-8" )
summary(estaciones)
##        X                Y                        NOMBRE   
##  Min.   :-58.46   Min.   :-34.64   15 DE NOVIEMBRE  :  1  
##  1st Qu.:-58.42   1st Qu.:-34.62   25 DE MAYO       :  1  
##  Median :-58.40   Median :-34.60   9 DE JULIO       :  1  
##  Mean   :-58.40   Mean   :-34.61   ACEVEDO          :  1  
##  3rd Qu.:-58.38   3rd Qu.:-34.59   ACUÑA DE FIGUEROA:  1  
##  Max.   :-58.36   Max.   :-34.57   ADUANA           :  1  
##                                    (Other)          :193  
##                                                           DOMICILIO  
##  PLAZA FUERZA AEREA: AV. DR. J. RAMOS MEJIA Y AV DEL LIBERTADOR:  2  
##  15 DE NOVIEMBRE DE 1889 2687 ENTRE CATAMARCA Y JUJUY          :  1  
##  25 DE MAYO Y LAVALLE                                          :  1  
##  33 ORIENTALES 1439, ENTRE AV. PAVON Y AV. GARAY               :  1  
##  9 DE JULIO Y MORENO                                           :  1  
##  ACEVEDO Y PADILLA                                             :  1  
##  (Other)                                                       :192  
##                      IMAGEN          AUTOMAT   
##  ESTACION_AUTOMATICA.PNG:199   AUTOMATICA:199  
##                                                
##                                                
##                                                
##                                                
##                                                
##                                                
##                                           OBSERV       NRO_EST     
##  ABRIL 2015 (PASO DE SER MANUAL A AUTOMATICA): 26   Min.   :  1.0  
##  mar-17                                      : 17   1st Qu.: 51.5  
##  abr-17                                      : 16   Median :101.0  
##  may-17                                      : 16   Mean   :100.9  
##  ago-17                                      : 11   3rd Qu.:150.5  
##  jul-17                                      : 11   Max.   :200.0  
##  (Other)                                     :102                  
##                                              HORARIO   
##  ESTACION AUTOMATICA: DISPONIBILIDAD LAS 24 HORAS:199  
##                                                        
##                                                        
##                                                        
##                                                        
##                                                        
##                                                        
##                                  DIRE_NORM  
##  DEL LIBERTADOR AV Y RAMOS MEJIA DR AV:  2  
##  1 ZAPIOLA                            :  1  
##  101 BALCARCE                         :  1  
##  101 VIAMONTE                         :  1  
##  1016 PERU                            :  1  
##  1027 SAAVDREA                        :  1  
##  (Other)                              :192
bicisCABA <- bicisCABA %>% 
    left_join(estaciones[c("X", "Y", "NOMBRE", "NRO_EST")], 
              by = c("bici_estacion_origen" = "NRO_EST"))

estaciones <- bicisCABA %>% filter(X.y <0, Y.y <0)

bbox <- c(min(estaciones$X.y, na.rm = TRUE),
          min(estaciones$X.y, na.rm = TRUE),
          max(estaciones$Y.y, na.rm = TRUE),
          max(estaciones$Y.y, na.rm = TRUE))
## Warning in min(estaciones$X.y, na.rm = TRUE): ningún argumento finito para
## min; retornando Inf

## Warning in min(estaciones$X.y, na.rm = TRUE): ningún argumento finito para
## min; retornando Inf
## Warning in max(estaciones$Y.y, na.rm = TRUE): ningun argumento finito para
## max; retornando -Inf

## Warning in max(estaciones$Y.y, na.rm = TRUE): ningun argumento finito para
## max; retornando -Inf

(borro chunk)

CABA <- get_stamenmap(bbox = bbox, maptype = “toner-lite”)

ggmap(CABA)

ggmap(CABA) + geom_point(data = estaciones, aes(x = X.y, y = Y.y))

ggmap(CABA) + geom_point(data = estaciones, aes(x = X.y, y = Y.y), color = “orange”, size = 0.1, alpha = 0.1)