bicis <- read.csv("C:/Users/Public/colectivo/bici.csv" ,fileEncoding="UTF-8",sep=",", stringsAsFactors =FALSE)
estaciones <- read.csv("C:/Users/Public/colectivo/estaciones.csv" ,fileEncoding="UTF-8",sep=",", stringsAsFactors =FALSE)
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.6.1
## Registered S3 method overwritten by 'rvest':
##   method            from
##   read_xml.response xml2
## -- 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.3
## v tidyr   0.8.3     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.4.0
## Warning: package 'purrr' was built under R version 3.6.1
## Warning: package 'dplyr' was built under R version 3.6.1
## -- Conflicts ------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
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.
library(sf)
## Warning: package 'sf' was built under R version 3.6.1
## Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
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/
library(dplyr)
library(purrr)
library(osmdata)
## Warning: package 'osmdata' was built under R version 3.6.1
## Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
bicis <- bicis %>%
  rename(origen="bici_nombre_estacion_origen") %>% 
  rename(destino="bici_nombre_estacion_destino")
estaciones_viejas <- st_read("C:/Users/Public/colectivo/zip/estaciones_de_bicicletas.shp")
## Reading layer `estaciones_de_bicicletas' from data source `C:\Users\Public\colectivo\zip\estaciones_de_bicicletas.shp' using driver `ESRI Shapefile'
## Simple feature collection with 199 features and 8 fields
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: 100755.7 ymin: 98616.85 xmax: 109815.6 ymax: 106787.5
## epsg (SRID):    NA
## proj4string:    +proj=tmerc +lat_0=-34.6297166 +lon_0=-58.4627 +k=0.9999980000000001 +x_0=100000 +y_0=100000 +ellps=intl +units=m +no_defs
espacios_verdes <- st_read("C:/Users/Public/colectivo/everdes/espacios-verdes-catastrales.shp")
## Reading layer `espacios-verdes-catastrales' from data source `C:\Users\Public\colectivo\everdes\espacios-verdes-catastrales.shp' using driver `ESRI Shapefile'
## Simple feature collection with 1358 features and 25 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -58.53175 ymin: -34.70481 xmax: -58.33981 ymax: -34.52654
## epsg (SRID):    4326
## proj4string:    +proj=longlat +datum=WGS84 +no_defs
conteo <- bicis %>% 
    group_by(origen, bici_estacion_origen, destino,bici_estacion_destino ) %>% 
    summarise(total=n())%>%
  arrange(total)%>%
rename(id_estacion="bici_estacion_origen")%>%
  rename(NRO_EST="bici_estacion_destino")
top10 <- conteo %>% 
    ungroup() %>% 
    filter(origen != destino) %>% 
    top_n(10)
## Selecting by total
top10_NO <- top10 %>% 
  mutate(id_estacion=ifelse(id_estacion==175,147,id_estacion))
ggplot() + 
    geom_tile(data = conteo, aes(x = origen, y = destino, fill = total)) +
    scale_fill_distiller(palette = "Spectral")

ggplot() + 
    geom_tile(data = top10, 
              aes(y = as.factor(origen),
                  x = as.factor(destino),
                  fill = total)) +
    scale_fill_distiller(palette = "Spectral")

estaciones_viejas <- estaciones_viejas %>%
mutate(lat = unlist(map(estaciones_viejas$geometry,1)),
long = unlist(map(estaciones_viejas$geometry,2)))
top10 <- top10 %>% 
  mutate(id_estacion=as.numeric(id_estacion)) %>% 
  mutate(NRO_EST=as.numeric(NRO_EST))
Viajes <- left_join(top10,estaciones)%>%
mutate(lat=as.numeric(lat)) %>% 
  mutate(long=as.numeric(long)) %>% 
rename(origen_lat = lat,
           origen_long = long)
## Joining, by = "id_estacion"
Viajes <- Viajes %>% 
  left_join(estaciones, 
              by = c("NRO_EST"= "id_estacion")) 
recorridos <- Viajes %>% 
    mutate(ID = paste(origen, "-", destino))
bbox <- make_bbox(Viajes$origen_long, Viajes$origen_lat)
mapa_base <- get_stamenmap(bbox, color = "bw", zoom = 12)
## Source : http://tile.stamen.com/terrain/12/1383/2467.png
## Source : http://tile.stamen.com/terrain/12/1383/2468.png
ggmap(mapa_base) +
    geom_point(data = Viajes, aes(x = origen_long, y = origen_lat), color = "red")

ggplot()+
  geom_sf(data=espacios_verdes, fill="green")

Consti <- c(name="Constitucion",long =-58.38093,lat=-34.62674)

Guemes <- c(name="Plaza Guemes", long= -58.41612,lat=-34.58943)

LasHeras <- c(name="Parque Las Heras", long= -58.40774,lat=-34.58544)

Ecuador<- c(name="Ecuador", long= -58.40461,lat=-34.59610)

EcoParque<- c(name="EcoParque", long= -58.41388,lat=-34.57551)

Italia<- c(name="Plaza Italia", long= -58.42095,lat=-34.58055)

Pena<- c(name="Pena", long= -58.39737,lat=-34.59082)

Congreso <- c(name="Plaza Congreso", long= -58.38934,lat=-34.6094218)

Lezama<- c(name="Parque Lezama", long= -58.36976,lat=-34.628526)
    Uno <- osrmRoute(src = Pena, 
                                 dst = LasHeras, 
                                 sp = TRUE, 
                                 overview = "full")
## Warning: sp is deprecated; use returnclass instead.
Nueve <- osrmRoute(src = Guemes, 
                                 dst = LasHeras, 
                                 sp = TRUE, 
            overview = "full")
## Warning: sp is deprecated; use returnclass instead.
Ocho <- osrmRoute(src = LasHeras, 
                                 dst = Guemes, 
                                 sp = TRUE, 
                                 overview = "full")
## Warning: sp is deprecated; use returnclass instead.
Siete <- osrmRoute(src = Ecuador, 
                                 dst = LasHeras, 
                                 sp = TRUE, 
                                 overview = "full")
## Warning: sp is deprecated; use returnclass instead.
Seis <- osrmRoute(src = Consti, 
                                 dst = Lezama, 
                                 sp = TRUE, 
                                 overview = "full")
## Warning: sp is deprecated; use returnclass instead.
Cinco <- osrmRoute(src = LasHeras, 
                                 dst = Ecuador, 
                                 sp = TRUE, 
                                 overview = "full")
## Warning: sp is deprecated; use returnclass instead.
Cuatro <- osrmRoute(src = EcoParque, 
                                 dst = Italia, 
                                 sp = TRUE, overview = "full")
## Warning: sp is deprecated; use returnclass instead.
Tres <- osrmRoute(src = Italia, 
                                 dst = EcoParque, 
                                 sp = TRUE, overview = "full")
## Warning: sp is deprecated; use returnclass instead.
Dos <- osrmRoute(src = LasHeras, 
                                 dst = Pena, 
                                 sp = TRUE, 
                                 overview = "full")
## Warning: sp is deprecated; use returnclass instead.
Diez <- osrmRoute(src = Consti, 
                                 dst = Congreso, 
                                 sp = TRUE, 
                                 overview = "full")
## Warning: sp is deprecated; use returnclass instead.
library(leaflet)
## Warning: package 'leaflet' was built under R version 3.6.1
leaflet(Uno) %>% 
    addTiles() %>% 
    addPolylines(color = "red")
EspaciosVerdes <- opq(bbox) %>% 
  add_osm_feature(key = "landuse", value = "greenfield") %>% 
  osmdata_sf() 
Recorridos <- rbind(Uno,Dos,Tres,Cuatro,Cinco,Seis,Siete,Ocho,Nueve,Diez)

Mapa del top 10 de recorridos no circulares

leaflet(Recorridos) %>% 
    addTiles() %>% 
    addPolylines(color = "red")

- En este mapa no pude discriminar por color, ni tamaño debido a incovenientes existentes a la hora de realizar los recorridos mediante otros metodos mas génericos.

ggmap(mapa_base,darken = 0.7) +
    geom_path(data = Recorridos, aes(x = long, y = lat,color="red"), alpha = 0.7, size=1.5) +
    theme_nothing()