PARADAS DE COLECTIVO EN CABA

library(tidyverse)
## 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.0.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(dplyr)
library(leaflet)
## Warning: package 'leaflet' was built under R version 3.6.1
library(purrr)
library(sf)
## Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
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
bounding_box <- getbb('CABA')
limites <- getbb('CABA', format_out = "sf_polygon")
comunas <- st_read('https://bitsandbricks.github.io/data/CABA_comunas.geojson')
## Reading layer `CABA_comunas' from data source `https://bitsandbricks.github.io/data/CABA_comunas.geojson' using driver `GeoJSON'
## Simple feature collection with 15 features and 4 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -58.53152 ymin: -34.70529 xmax: -58.33514 ymax: -34.52754
## epsg (SRID):    4326
## proj4string:    +proj=longlat +datum=WGS84 +no_defs
barrios <- st_read('https://bitsandbricks.github.io/data/CABA_barrios.geojson')
## Reading layer `CABA_barrios' from data source `https://bitsandbricks.github.io/data/CABA_barrios.geojson' using driver `GeoJSON'
## Simple feature collection with 48 features and 4 fields
## geometry type:  POLYGON
## dimension:      XY
## bbox:           xmin: -58.53152 ymin: -34.70529 xmax: -58.33514 ymax: -34.52754
## epsg (SRID):    4326
## proj4string:    +proj=longlat +datum=WGS84 +no_defs
bondi <- read.csv2("C:/Users/Tomás Mestre Olmedo/OneDrive/UTDT/Ciencia de Datos 2/colectivo/paradabondi.csv",fileEncoding="latin1",sep=";", stringsAsFactors =FALSE)
bondibarrio <- bondi %>% 
  st_as_sf(coords=c ("X","Y"), crs=4326)

Mapa de la distribución geógrafica

bondibarrioS <- st_join(barrios,bondibarrio)
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
ggplot(barrios) +
    geom_sf(data = barrios) +
  geom_point(data = bondi, aes(x = X, y = Y),
               alpha = .15, 
               color = "red")+
  labs(title = "Paradas de colectivo en CABA",
         subtitle = "Ciudad Autónoma de Buenos Aires, 2019",
         caption = "Fuente: Elaboración propia con base de datos GCBA")

bondixbarrio <- bondibarrioS %>% 
  group_by(BARRIO,COMUNA)%>%
 summarise(freq=n()) 
ggplot(bondixbarrio)+ geom_bar(aes(x= as.factor(BARRIO),weight =freq,fill=BARRIO))+
  coord_flip()+
  labs(title = "Cantidad de paradas de colectivo ",
         caption = "Fuente: Elaboración propia con base de datos GCBA",
         x = "Cantidad de paradas de colectivo",
         y = "Barrio")

Concentración espacial de las paradas de colectivo por barrio

ggplot(bondixbarrio)+
    geom_sf(data =bondixbarrio, aes(fill=freq),color=NA) +
  scale_fill_gradient(low = "yellow", high = "red")+
  labs(title = "Paradas de colectivo por barrio",
         subtitle = "Ciudad Autónoma de Buenos Aires, 2019",
         caption = "Fuente: Elaboración propia con base de datos GCBA")

bbox <- getbb("Ciudad Autonoma de Buenos Aires")
bbox
##         min       max
## x -58.53146 -58.33512
## y -34.70564 -34.52655
bbox_poly <- getbb("Ciudad Autonoma de Buenos Aires", format_out = "sf_polygon")
caba <- opq(bbox) %>% 
    add_osm_feature(key = "highway")
caba <- caba %>% 
    osmdata_sf()
calles <- caba$osm_lines
calles <- calles %>% 
  mutate(maxspeed = as.numeric(maxspeed),
         lanes = ifelse(is.na(lanes), 1, as.numeric(lanes)))
ggplot(calles) +
  geom_sf(aes(color = maxspeed), alpha = 0.5) +
    scale_color_viridis_c() +
      theme_void() +
    labs(title = "CABA",
         subtitle = "Vías de circulación",
         caption = "Fuente: OpenStreetMap",
         color = "Velocidad máxima")

ggplot() +
    geom_sf(data = filter(calles, str_detect(name, "Av")), 
            color = "gray40") +
    theme_void() +
      labs(title = "CABA",
         subtitle = "Avenidas",
         caption = "Fuente: OpenStreetMap")

bondi2 <- opq(bbox) %>% 
  add_osm_feature(key = "highway", value = "bus_stop") %>% 
  osmdata_sf() 
## Request failed [429]. Retrying in 1 seconds...
Caba_bondi2 <- st_intersection(bondi2$osm_points, bbox_poly)
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant
## throughout all geometries
ggplot() +
  geom_sf(data = Caba_bondi2, color="red")

BondiBarrios2 <- st_join(barrios,Caba_bondi2)
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
BondixBarrio2 <- BondiBarrios2 %>% 
  group_by(BARRIO,COMUNA)%>%
 summarise(freq=n()) 
ggplot() +
geom_sf(data = BondixBarrio2, aes(fill=freq))