R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(utils)
library(leaflet)
library(ggplot2)
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:lubridate':
## 
##     intersect, setdiff, union
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
url= "https://raw.githubusercontent.com/aaizemberg/vis/gh-pages/bataxi/bataxi.csv"
bataxi=read.csv(url)
# -------------------------- TABLA TAXISTAS ------------------------------------
bataxi$minutos = round(((bataxi$duracion)/60),2)

taxistas= bataxi%>%
  group_by(id_taxista_r)%>%
  summarise(viajes=n(), minutos=sum(minutos),horas=round(minutos/60, 2))%>%
  arrange(-viajes)

head(taxistas, 10)
## # A tibble: 10 x 4
##    id_taxista_r viajes minutos horas
##           <int>  <int>   <dbl> <dbl>
##  1          857    173   2530.  42.2
##  2          883    166   2640.  44  
##  3          594    158   2556.  42.6
##  4          664    158   2482.  41.4
##  5            8    143   2121.  35.4
##  6          105    142   2344.  39.1
##  7          295    142   2131.  35.5
##  8          815    135   2046.  34.1
##  9          692     99   1603.  26.7
## 10          142     95   1575.  26.3
# -------------------------- MAPA ORIGEN ------------------------------------
leaflet(bataxi) %>%
  addTiles() %>%
  addMarkers(~bataxi$origen_viaje_x, ~bataxi$origen_viaje_y,labelOptions = labelOptions(noHide = F),clusterOptions = markerClusterOptions(),popup = paste0("<b> Taxista: </b>", bataxi$id_taxista_r , "<br/><b> Duracion: </b>", bataxi$minutos, "<br> <b> Cant pasajeros: </b>", bataxi$cantidad_pasajeros)
  ) %>% 
  setView(-58.45, -34.62, zoom =11.5)%>%
  addProviderTiles("CartoDB.Positron")
# -------------------------- MAPA DESTINO ------------------------------------
leaflet(bataxi) %>%
  addTiles() %>%
  addMarkers(~bataxi$destino_viaje_x, ~bataxi$destino_viaje_y,labelOptions = labelOptions(noHide = F),clusterOptions = markerClusterOptions(),popup = paste0("<b> Taxista: </b>", bataxi$id_taxista_r , "<br/><b> Duracion: </b>", bataxi$minutos, "<br> <b> Cant pasajeros: </b>", bataxi$cantidad_pasajeros)
  ) %>% 
  setView(-58.45, -34.62, zoom =11.5)%>%
  addProviderTiles("CartoDB.Positron")
# -------------------------- EVOLUCION CANTIDAD DE VIAJES ------------------------------------
bataxi$fecha=date(bataxi$fecha_inicio)

viajes <- bataxi %>% 
  group_by(date = fecha) %>% 
  summarise(viajes = n()) %>% 
  mutate(year = year(date)) %>% 
  mutate(month = month(date)) %>% 
  mutate (month_year =(paste(month, year, sep = "- ")))

viajes %>%
  ggplot(aes(x=date, y=viajes))+
  geom_smooth(color = "#FF5A5F")+
  geom_line( color="grey") +
  geom_point(shape=21, color = "#007A87",  fill="#007A87", size=1) +
  scale_x_date(date_breaks = "months" , date_labels = "%b-%y") +
  ggtitle("Evolución de los viajes en 2017")
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'