TAREA 1 - MĆDULO 2
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.1.0 v dplyr 1.0.5
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(sf)
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
comunas_caba <- st_read("comunas_caba.geojson", stringsAsFactors = TRUE)
## Reading layer `comuna' from data source `C:\Users\User\Desktop\Tarea M2\comunas_caba.geojson' using driver `GeoJSON'
## Simple feature collection with 15 features and 6 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -58.53152 ymin: -34.70529 xmax: -58.33515 ymax: -34.52649
## Geodetic CRS: WGS 84
summary(comunas_caba)
## BARRIOS
## AGRONOMIA - CHACARITA - PARQUE CHAS - PATERNAL - VILLA CRESPO - VILLA ORTUZAR:1
## ALMAGRO - BOEDO :1
## BALVANERA - SAN CRISTOBAL :1
## BARRACAS - BOCA - NUEVA POMPEYA - PARQUE PATRICIOS :1
## BELGRANO - COLEGIALES - NUĆEZ :1
## CABALLITO :1
## (Other) :9
## PERIMETRO AREA comuna ID
## Min. :10486 Min. : 6317265 Min. : 1.0 Min. : 1.0
## 1st Qu.:17532 1st Qu.: 9636965 1st Qu.: 4.5 1st Qu.: 4.5
## Median :19988 Median :14322897 Median : 8.0 Median : 8.0
## Mean :20587 Mean :13604581 Mean : 8.0 Mean : 8.0
## 3rd Qu.:21790 3rd Qu.:16175589 3rd Qu.:11.5 3rd Qu.:11.5
## Max. :36102 Max. :22216902 Max. :15.0 Max. :15.0
##
## OBJETO geometry
## LIMITE COMUNAL:15 MULTIPOLYGON :15
## epsg:4326 : 0
## +proj=long...: 0
##
##
##
##
head(comunas_caba)
## Simple feature collection with 6 features and 6 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -58.53152 ymin: -34.67451 xmax: -58.3707 ymax: -34.56827
## Geodetic CRS: WGS 84
## BARRIOS
## 1 RECOLETA
## 2 ALMAGRO - BOEDO
## 3 CABALLITO
## 4 FLORES - PARQUE CHACABUCO
## 5 LINIERS - MATADEROS - PARQUE AVELLANEDA
## 6 FLORESTA - MONTE CASTRO - VELEZ SARSFIELD - VERSALLES - VILLA LURO - VILLA REAL
## PERIMETRO AREA comuna ID OBJETO geometry
## 1 21452.84 6317265 2 1 LIMITE COMUNAL MULTIPOLYGON (((-58.38 -34....
## 2 12323.43 6660603 5 2 LIMITE COMUNAL MULTIPOLYGON (((-58.41287 -...
## 3 10990.96 6851029 6 3 LIMITE COMUNAL MULTIPOLYGON (((-58.43061 -...
## 4 17972.26 12422901 7 4 LIMITE COMUNAL MULTIPOLYGON (((-58.452 -34...
## 5 21411.74 16505306 9 5 LIMITE COMUNAL MULTIPOLYGON (((-58.51925 -...
## 6 18332.04 12656557 10 6 LIMITE COMUNAL MULTIPOLYGON (((-58.48834 -...
class(comunas_caba)
## [1] "sf" "data.frame"
ggplot(comunas_caba)+
geom_sf()
MAPEO DE UNA VARIABLE NUMĆRICA
ggplot(comunas_caba)+
geom_sf(aes(fill=AREA), color="white")+
labs(title = "Comunas CABA",
subtitle = "Ćrea")
MAPEO DE UNA VARIABLE CATEGĆRICA
comunas_caba <- mutate(comunas_caba, CATEGORIA=if_else(AREA>=10000000, "MAYOR A 14000000", "MENOR A 14000000"))
ggplot(comunas_caba)+
geom_sf(aes(fill=CATEGORIA))+
labs(title = "Comunas CABA",
subtitle = "Ćrea")
TAREA 2 - MĆDULO 2
sensores_transito <- read.csv("sensores.csv", stringsAsFactors = TRUE)
summary(sensores_transito)
## long lat id_sensor sistema_co
## Min. :-58.53 Min. :-34.66 Min. : 1.00 COUNTITS :40
## 1st Qu.:-58.42 1st Qu.:-34.62 1st Qu.: 7.00 TRAFFICAMS:12
## Median :-58.39 Median :-34.61 Median :14.50
## Mean :-58.42 Mean :-34.61 Mean :17.27
## 3rd Qu.:-58.38 3rd Qu.:-34.60 3rd Qu.:27.25
## Max. :-58.38 Max. :-34.54 Max. :40.00
##
## ubicacion ubicacion_
## AV. RIVADAVIA Y AV. PUEYRREDON : 2 :42
## AV. DONADO Y ARIAS : 1 SANTA FE AV. : 3
## AV. 9 DE JULIO (SENTIDO SUR) Y AV. INDEPENDENCIA: 1 CERRITO : 2
## AV. BELGRANO Y AV. ENTRE RIOS (SOBRE B) : 1 BELGRANO AV. : 1
## AV. BELGRANO Y AV. ENTRE RIOS (SOBRE ER) : 1 CALLAO AV. : 1
## AV. BELGRANO Y LIMA : 1 ENTRE RIOS AV.: 1
## (Other) :45 (Other) : 2
## aĆ.o_insta direccion_
## Min. :2011 ALBERDI, JUAN BAUTISTA AV. Y SALADILLO: 2
## 1st Qu.:2015 BELGRANO AV. Y ENTRE RIOS AV. : 2
## Median :2016 CASTRO, EMILIO AV. Y SALADILLO : 2
## Mean :2015 DEL LIBERTADOR AV. Y CERRITO : 2
## 3rd Qu.:2016 DIRECTORIO AV. Y BRUIX AV. : 2
## Max. :2016 JUJUY AV. Y BELGRANO AV. : 2
## (Other) :40
## calle cruce barrio
## SANTA FE AV. : 6 CERRITO : 5 BALVANERA :11
## DEL LIBERTADOR AV. : 4 LIMA : 5 RECOLETA : 7
## JUJUY AV. : 4 PUEYRREDON AV.: 5 RETIRO : 6
## RIVADAVIA AV. : 4 ENTRE RIOS AV.: 4 MONSERRAT : 4
## 9 DE JULIO AV. : 3 SALADILLO : 4 CONSTITUCION: 3
## ALBERDI, JUAN BAUTISTA AV.: 3 CALLAO AV. : 3 LINIERS : 3
## (Other) :28 (Other) :26 (Other) :18
## comuna
## Min. : 1.000
## 1st Qu.: 1.000
## Median : 3.000
## Mean : 4.442
## 3rd Qu.: 9.000
## Max. :14.000
##
ggplot(sensores_transito) +
geom_point(aes(x=long, y=lat))
ggplot()+
geom_sf(data=comunas_caba, fill="gray75", color="white")+
geom_point(data=sensores_transito, aes(x=long, y=lat, color=comuna),alpha=0.5)+
labs(title="Sensores de trƔnsito en CABA")
Unión espacial
sensores_geo <- sensores_transito %>%
st_as_sf(coords = c("long", "lat"), crs = 4326)
class(sensores_geo)
## [1] "sf" "data.frame"
head(sensores_geo)
## Simple feature collection with 6 features and 10 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -58.40352 ymin: -34.61884 xmax: -58.38252 ymax: -34.59547
## Geodetic CRS: WGS 84
## id_sensor sistema_co ubicacion ubicacion_
## 1 1 COUNTITS AV. JUJUY Y AV. INDEPENDENCIA
## 2 2 COUNTITS AV. ENTRE RIOS Y AV. RIVADAVIA
## 3 3 COUNTITS AV. CORDOBA Y CERRITO
## 4 4 COUNTITS AV. BELGRANO Y AV. ENTRE RIOS (SOBRE B) BELGRANO AV.
## 5 5 COUNTITS AV. BELGRANO Y AV. ENTRE RIOS (SOBRE ER) ENTRE RIOS AV.
## 6 6 COUNTITS AV. SANTA FE Y CERRITO (SOBRE C) CERRITO
## aĆ.o_insta direccion_ calle cruce
## 1 2015 JUJUY AV. E INDEPENDENCIA AV. JUJUY AV. INDEPENDENCIA AV.
## 2 2015 ENTRE RIOS AV. Y RIVADAVIA AV. ENTRE RIOS AV. RIVADAVIA AV.
## 3 2015 CORDOBA AV. Y CERRITO CORDOBA AV. CERRITO
## 4 2016 BELGRANO AV. Y ENTRE RIOS AV. BELGRANO AV. ENTRE RIOS AV.
## 5 2016 BELGRANO AV. Y ENTRE RIOS AV. BELGRANO AV. ENTRE RIOS AV.
## 6 2016 SANTA FE AV. Y CERRITO SANTA FE AV. CERRITO
## barrio comuna geometry
## 1 BALVANERA 3 POINT (-58.40352 -34.61884)
## 2 BALVANERA 3 POINT (-58.39196 -34.60917)
## 3 RETIRO 1 POINT (-58.38252 -34.59909)
## 4 BALVANERA 3 POINT (-58.39171 -34.61382)
## 5 BALVANERA 3 POINT (-58.39171 -34.61382)
## 6 RETIRO 1 POINT (-58.38272 -34.59547)
summary(sensores_geo)
## id_sensor sistema_co
## Min. : 1.00 COUNTITS :40
## 1st Qu.: 7.00 TRAFFICAMS:12
## Median :14.50
## Mean :17.27
## 3rd Qu.:27.25
## Max. :40.00
##
## ubicacion ubicacion_
## AV. RIVADAVIA Y AV. PUEYRREDON : 2 :42
## AV. DONADO Y ARIAS : 1 SANTA FE AV. : 3
## AV. 9 DE JULIO (SENTIDO SUR) Y AV. INDEPENDENCIA: 1 CERRITO : 2
## AV. BELGRANO Y AV. ENTRE RIOS (SOBRE B) : 1 BELGRANO AV. : 1
## AV. BELGRANO Y AV. ENTRE RIOS (SOBRE ER) : 1 CALLAO AV. : 1
## AV. BELGRANO Y LIMA : 1 ENTRE RIOS AV.: 1
## (Other) :45 (Other) : 2
## aĆ.o_insta direccion_
## Min. :2011 ALBERDI, JUAN BAUTISTA AV. Y SALADILLO: 2
## 1st Qu.:2015 BELGRANO AV. Y ENTRE RIOS AV. : 2
## Median :2016 CASTRO, EMILIO AV. Y SALADILLO : 2
## Mean :2015 DEL LIBERTADOR AV. Y CERRITO : 2
## 3rd Qu.:2016 DIRECTORIO AV. Y BRUIX AV. : 2
## Max. :2016 JUJUY AV. Y BELGRANO AV. : 2
## (Other) :40
## calle cruce barrio
## SANTA FE AV. : 6 CERRITO : 5 BALVANERA :11
## DEL LIBERTADOR AV. : 4 LIMA : 5 RECOLETA : 7
## JUJUY AV. : 4 PUEYRREDON AV.: 5 RETIRO : 6
## RIVADAVIA AV. : 4 ENTRE RIOS AV.: 4 MONSERRAT : 4
## 9 DE JULIO AV. : 3 SALADILLO : 4 CONSTITUCION: 3
## ALBERDI, JUAN BAUTISTA AV.: 3 CALLAO AV. : 3 LINIERS : 3
## (Other) :28 (Other) :26 (Other) :18
## comuna geometry
## Min. : 1.000 POINT :52
## 1st Qu.: 1.000 epsg:4326 : 0
## Median : 3.000 +proj=long...: 0
## Mean : 4.442
## 3rd Qu.: 9.000
## Max. :14.000
##
ggplot(sensores_geo)+
geom_sf()
sensores_geo <- st_join(sensores_geo, comunas_caba)
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
summary(sensores_geo)
## id_sensor sistema_co
## Min. : 1.00 COUNTITS :40
## 1st Qu.: 7.00 TRAFFICAMS:12
## Median :14.50
## Mean :17.27
## 3rd Qu.:27.25
## Max. :40.00
##
## ubicacion ubicacion_
## AV. RIVADAVIA Y AV. PUEYRREDON : 2 :42
## AV. DONADO Y ARIAS : 1 SANTA FE AV. : 3
## AV. 9 DE JULIO (SENTIDO SUR) Y AV. INDEPENDENCIA: 1 CERRITO : 2
## AV. BELGRANO Y AV. ENTRE RIOS (SOBRE B) : 1 BELGRANO AV. : 1
## AV. BELGRANO Y AV. ENTRE RIOS (SOBRE ER) : 1 CALLAO AV. : 1
## AV. BELGRANO Y LIMA : 1 ENTRE RIOS AV.: 1
## (Other) :45 (Other) : 2
## aĆ.o_insta direccion_
## Min. :2011 ALBERDI, JUAN BAUTISTA AV. Y SALADILLO: 2
## 1st Qu.:2015 BELGRANO AV. Y ENTRE RIOS AV. : 2
## Median :2016 CASTRO, EMILIO AV. Y SALADILLO : 2
## Mean :2015 DEL LIBERTADOR AV. Y CERRITO : 2
## 3rd Qu.:2016 DIRECTORIO AV. Y BRUIX AV. : 2
## Max. :2016 JUJUY AV. Y BELGRANO AV. : 2
## (Other) :40
## calle cruce barrio
## SANTA FE AV. : 6 CERRITO : 5 BALVANERA :11
## DEL LIBERTADOR AV. : 4 LIMA : 5 RECOLETA : 7
## JUJUY AV. : 4 PUEYRREDON AV.: 5 RETIRO : 6
## RIVADAVIA AV. : 4 ENTRE RIOS AV.: 4 MONSERRAT : 4
## 9 DE JULIO AV. : 3 SALADILLO : 4 CONSTITUCION: 3
## ALBERDI, JUAN BAUTISTA AV.: 3 CALLAO AV. : 3 LINIERS : 3
## (Other) :28 (Other) :26 (Other) :18
## comuna.x
## Min. : 1.000
## 1st Qu.: 1.000
## Median : 3.000
## Mean : 4.442
## 3rd Qu.: 9.000
## Max. :14.000
##
## BARRIOS
## CONSTITUCION - MONSERRAT - PUERTO MADERO - RETIRO - SAN NICOLAS - SAN TELMO:14
## BALVANERA - SAN CRISTOBAL :13
## LINIERS - MATADEROS - PARQUE AVELLANEDA : 8
## RECOLETA : 7
## BARRACAS - BOCA - NUEVA POMPEYA - PARQUE PATRICIOS : 3
## COGHLAN - SAAVEDRA - VILLA PUEYRREDON - VILLA URQUIZA : 2
## (Other) : 5
## PERIMETRO AREA comuna.y ID
## Min. :10486 Min. : 6317265 Min. : 1.000 Min. : 1.000
## 1st Qu.:11864 1st Qu.: 6385991 1st Qu.: 1.000 1st Qu.: 5.000
## Median :21453 Median :15845871 Median : 3.000 Median :10.000
## Mean :23174 Mean :12890828 Mean : 4.442 Mean : 9.019
## 3rd Qu.:36102 3rd Qu.:17794569 3rd Qu.: 9.000 3rd Qu.:14.000
## Max. :36102 Max. :21684645 Max. :14.000 Max. :15.000
##
## OBJETO CATEGORIA geometry
## LIMITE COMUNAL:52 Length:52 POINT :52
## Class :character epsg:4326 : 0
## Mode :character +proj=long...: 0
##
##
##
##
sensores_geo <- sensores_geo %>%
group_by(comuna.x) %>%
summarise(cantidad=n())
## although coordinates are longitude/latitude, st_union assumes that they are planar
## although coordinates are longitude/latitude, st_union assumes that they are planar
## although coordinates are longitude/latitude, st_union assumes that they are planar
## although coordinates are longitude/latitude, st_union assumes that they are planar
## although coordinates are longitude/latitude, st_union assumes that they are planar
## although coordinates are longitude/latitude, st_union assumes that they are planar
## although coordinates are longitude/latitude, st_union assumes that they are planar
## although coordinates are longitude/latitude, st_union assumes that they are planar
## although coordinates are longitude/latitude, st_union assumes that they are planar
## although coordinates are longitude/latitude, st_union assumes that they are planar
head(sensores_geo)
## Simple feature collection with 6 features and 2 fields
## Geometry type: GEOMETRY
## Dimension: XY
## Bounding box: xmin: -58.52642 ymin: -34.66148 xmax: -58.38069 ymax: -34.58703
## Geodetic CRS: WGS 84
## # A tibble: 6 x 3
## comuna.x cantidad geometry
## <int> <int> <GEOMETRY [°]>
## 1 1 14 MULTIPOINT ((-58.38272 -34.59547), (-58.38252 -34.59909), (~
## 2 2 7 MULTIPOINT ((-58.40235 -34.59444), (-58.39332 -34.59586), (~
## 3 3 13 MULTIPOINT ((-58.40597 -34.61012), (-58.40491 -34.61464), (~
## 4 4 3 MULTIPOINT ((-58.41641 -34.65473), (-58.38845 -34.65819))
## 5 5 1 POINT (-58.42101 -34.61148)
## 6 9 8 MULTIPOINT ((-58.52642 -34.63915), (-58.52388 -34.65589), (~
sensores_geo <- sensores_geo %>%
st_set_geometry(NULL)
head(sensores_geo)
## # A tibble: 6 x 2
## comuna.x cantidad
## <int> <int>
## 1 1 14
## 2 2 7
## 3 3 13
## 4 4 3
## 5 5 1
## 6 9 8
comunas_caba <- left_join(comunas_caba, sensores_geo, by= c("comuna" = "comuna.x"))
ggplot()+
geom_sf(data=comunas_caba, aes(fill=cantidad))+
labs(title = "Sensores de trƔnsito de CABA",
subtitle = "Densidad por Comuna",
fill = "Cantidad/Comuna")
TAREA 3 - MĆDULO 2
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(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
En esta oportunidad voy a analizar una base de datos que contiene las obras registradas en la Ciudad de Buenos Aires durante 2019
obras_2019 <- read.csv("BASE_OBRAS.csv", stringsAsFactors = TRUE, sep = "|")
Tuve que agregar el separador pipe para que no me desplazara las columnas porque algunas direcciones tenĆan ā,ā. Previamente, en el archivo .csv reemplacĆ© todas las tabulaciones por pipes
Fuente: https://www.rdocumentation.org/packages/iotools/versions/0.3-1/topics/read.csv.raw
La base de datos cuenta con 1717 registros y 20 variables
dim(obras_2019)
## [1] 1717 20
summary(obras_2019)
## Seccion Manzana Parcela SMP
## 65 : 53 58 : 22 16 : 53 None- - : 10
## 63 : 46 70 : 21 15 : 47 019-005-025: 3
## 19 : 45 34 : 18 2 : 46 025-059-026: 3
## 43 : 45 53 : 18 22 : 46 042-041-022: 3
## 83 : 45 27 : 17 3 : 45 049-134-011: 3
## 33 : 42 30 : 17 11 : 44 071-022-008: 3
## (Other):1441 (Other):1604 (Other):1436 (Other) :1692
## Expediente Nomenclacion.par Fecha.de.registro
## 16079848/19: 6 16/1/2019 : 9 18/7/2019: 54
## 30958421/18: 6 17-33-76-11/12/21 : 6 2/1/2019 : 54
## 10872986/17: 4 20-3-53-5/16/6a : 6 7/12/2019: 40
## 18101807/18: 4 12-4-31-8/9/10/15 : 4 7/11/2019: 37
## 18104411/18: 4 15-43-177-16a/21a : 4 31/7/2019: 35
## 18184115/17: 4 17-035-100-028/029: 4 29/7/2019: 31
## (Other) :1689 (Other) :1684 (Other) :1466
## Direccion Comuna.1 Codigo.postal
## J.NEWBERY 3431/61: 6 Comuna 12:264 Min. :1003
## PARAGUAY 460/76 : 6 Comuna 11:188 1st Qu.:1406
## BOYACA 602/14 : 4 Comuna 13:165 Median :1417
## CASTILLO 1659/67 : 4 Comuna 15:152 Mean :1375
## COCHABAMBA 354/70: 4 Comuna 14:142 3rd Qu.:1428
## GUATEMALA 5621/29: 4 Comuna 10:121 Max. :1440
## (Other) :1689 (Other) :685 NA's :7
## Codigo.postal.argentino Tipo.obra Superficie..m2.
## C1057AAD: 6 Micro Obra:261 Min. : 1.0
## C1427EGA: 6 Obra Mayor:525 1st Qu.: 129.5
## : 5 Obra Media:504 Median : 609.4
## C1023AAD: 4 Obra Menor:427 Mean : 1649.1
## C1150AAD: 4 3rd Qu.: 1649.0
## C1406BHL: 4 Max. :81124.6
## (Other) :1688 NA's :213
## Direccion.normalizada Lon Lat
## NEWBERY, JORGE AV. 3431: 6 Min. :-58.53 Min. :-34.69
## PARAGUAY 460 : 6 1st Qu.:-58.49 1st Qu.:-34.62
## BONIFACIO, JOSE 1502 : 4 Median :-58.46 Median :-34.60
## BOYACA 602 : 4 Mean :-58.46 Mean :-34.60
## CASTILLO 1659 : 4 3rd Qu.:-58.43 3rd Qu.:-34.58
## COCHABAMBA 354 : 4 Max. :-58.34 Max. :-34.54
## (Other) :1689
## Calle Altura Barrio
## QUESADA : 14 1055 : 6 PALERMO : 75
## BONIFACIO, JOSE : 13 1631 : 6 Palermo : 67
## ARANGUREN, JUAN F., DR.: 12 1638 : 6 Villa Urquiza: 61
## CORDOBA AV. : 12 2256 : 6 Caballito : 60
## PARAGUAY : 11 3431 : 6 CABALLITO : 59
## NUĆĘĆ¢\200\230EZ : 10 460 : 6 VILLA URQUIZA: 55
## (Other) :1645 (Other):1681 (Other) :1340
## Comuna
## Min. : 1.000
## 1st Qu.: 6.000
## Median :11.000
## Mean : 9.536
## 3rd Qu.:13.000
## Max. :15.000
## NA's :26
ANALISIS TEMPORAL
str(obras_2019)
## 'data.frame': 1717 obs. of 20 variables:
## $ Seccion : Factor w/ 99 levels " ","0.39","1",..: 27 25 25 50 29 72 72 93 46 36 ...
## $ Manzana : Factor w/ 383 levels " ",".252a","0",..: 354 326 330 100 262 333 342 293 335 194 ...
## $ Parcela : Factor w/ 251 levels ""," ","0","0000M",..: 186 165 54 165 174 192 174 171 174 213 ...
## $ SMP : Factor w/ 1517 levels " - - ",".39-088-002d",..: 388 357 360 822 394 1196 1185 1474 730 529 ...
## $ Expediente : Factor w/ 1478 levels "10051482/18",..: 1260 308 332 64 89 882 1015 662 1344 113 ...
## $ Nomenclacion.par : Factor w/ 1464 levels "","001-046-65C",..: 737 721 723 388 1439 500 489 637 1421 1064 ...
## $ Fecha.de.registro : Factor w/ 156 levels "1/2/2019","1/3/2019",..: 65 65 11 113 128 103 44 55 44 68 ...
## $ Direccion : Factor w/ 1477 levels "11 DE SEPT. 3966/74",..: 3 4 5 6 10 16 17 18 19 20 ...
## $ Comuna.1 : Factor w/ 15 levels "Comuna 1","Comuna 10",..: 5 5 5 7 9 3 3 2 12 7 ...
## $ Codigo.postal : int 1429 1429 1429 1427 1242 1416 1416 1407 1405 1427 ...
## $ Codigo.postal.argentino: Factor w/ 1426 levels ""," ","C1003AAN",..: 1140 1137 1138 1026 201 627 689 492 297 1024 ...
## $ Tipo.obra : Factor w/ 4 levels "Micro Obra","Obra Mayor",..: 4 3 1 4 3 4 3 4 4 3 ...
## $ Superficie..m2. : num 260.7 1024.3 22.1 253.2 1165.1 ...
## $ Direccion.normalizada : Factor w/ 1473 levels "11 DE SEPTIEMBRE DE 1888 2951",..: 4 1 2 5 9 287 63 893 886 66 ...
## $ Lon : num -58.5 -58.5 -58.5 -58.5 -58.4 ...
## $ Lat : num -34.5 -34.6 -34.5 -34.6 -34.6 ...
## $ Calle : Factor w/ 673 levels "11 DE SEPTIEMBRE DE 1888",..: 1 1 1 2 5 124 30 405 401 31 ...
## $ Altura : Factor w/ 1278 levels "1002","1005",..: 815 529 613 1248 159 403 579 1009 1118 83 ...
## $ Barrio : Factor w/ 96 levels "Agronomia","AGRONOMIA",..: 38 38 38 83 61 73 73 81 15 17 ...
## $ Comuna : int 13 13 13 15 3 11 11 10 6 15 ...
obras_2019 <- obras_2019 %>%
mutate(fecha=dmy(Fecha.de.registro))
str(obras_2019)
## 'data.frame': 1717 obs. of 21 variables:
## $ Seccion : Factor w/ 99 levels " ","0.39","1",..: 27 25 25 50 29 72 72 93 46 36 ...
## $ Manzana : Factor w/ 383 levels " ",".252a","0",..: 354 326 330 100 262 333 342 293 335 194 ...
## $ Parcela : Factor w/ 251 levels ""," ","0","0000M",..: 186 165 54 165 174 192 174 171 174 213 ...
## $ SMP : Factor w/ 1517 levels " - - ",".39-088-002d",..: 388 357 360 822 394 1196 1185 1474 730 529 ...
## $ Expediente : Factor w/ 1478 levels "10051482/18",..: 1260 308 332 64 89 882 1015 662 1344 113 ...
## $ Nomenclacion.par : Factor w/ 1464 levels "","001-046-65C",..: 737 721 723 388 1439 500 489 637 1421 1064 ...
## $ Fecha.de.registro : Factor w/ 156 levels "1/2/2019","1/3/2019",..: 65 65 11 113 128 103 44 55 44 68 ...
## $ Direccion : Factor w/ 1477 levels "11 DE SEPT. 3966/74",..: 3 4 5 6 10 16 17 18 19 20 ...
## $ Comuna.1 : Factor w/ 15 levels "Comuna 1","Comuna 10",..: 5 5 5 7 9 3 3 2 12 7 ...
## $ Codigo.postal : int 1429 1429 1429 1427 1242 1416 1416 1407 1405 1427 ...
## $ Codigo.postal.argentino: Factor w/ 1426 levels ""," ","C1003AAN",..: 1140 1137 1138 1026 201 627 689 492 297 1024 ...
## $ Tipo.obra : Factor w/ 4 levels "Micro Obra","Obra Mayor",..: 4 3 1 4 3 4 3 4 4 3 ...
## $ Superficie..m2. : num 260.7 1024.3 22.1 253.2 1165.1 ...
## $ Direccion.normalizada : Factor w/ 1473 levels "11 DE SEPTIEMBRE DE 1888 2951",..: 4 1 2 5 9 287 63 893 886 66 ...
## $ Lon : num -58.5 -58.5 -58.5 -58.5 -58.4 ...
## $ Lat : num -34.5 -34.6 -34.5 -34.6 -34.6 ...
## $ Calle : Factor w/ 673 levels "11 DE SEPTIEMBRE DE 1888",..: 1 1 1 2 5 124 30 405 401 31 ...
## $ Altura : Factor w/ 1278 levels "1002","1005",..: 815 529 613 1248 159 403 579 1009 1118 83 ...
## $ Barrio : Factor w/ 96 levels "Agronomia","AGRONOMIA",..: 38 38 38 83 61 73 73 81 15 17 ...
## $ Comuna : int 13 13 13 15 3 11 11 10 6 15 ...
## $ fecha : Date, format: "2019-05-21" "2019-05-21" ...
Luego de la ejecución de estas funciones, el campo fecha dejó de ser factor y pasó a ser āDateā, por lo tanto ya se puede trabajar con la variable fecha.
obras_2019 <- obras_2019 %>%
mutate(tiempo=today()-fecha)
head(obras_2019)
## Seccion Manzana Parcela SMP Expediente Nomenclacion.par
## 1 29 84b 21 029-84b-021 34915804/18 16-29-84b-21
## 2 27 72 11 027-072-011 18781034/18 16-27-72-11
## 3 27 75 009a 027-075-009a 19346833/18 16-27-75-009A
## 4 49 134 11 049-134-011 12279250/18 15-49-134-11
## 5 30 42 16 030-042-016 13113507/18 8-30-42-16
## 6 69 77 25 069-077-025 30348622/18 15-69-77-25
## Fecha.de.registro Direccion Comuna.1 Codigo.postal
## 1 21/5/2019 11 DE SEPT.4176 Comuna 13 1429
## 2 21/5/2019 11 DE SEPTIEMBRE 2951/57 Comuna 13 1429
## 3 11/3/2019 11 DE SEPTIEMBRE 3201/05 Comuna 13 1429
## 4 3/1/2019 14 DE JULIO 882 Comuna 15 1427
## 5 4/4/2019 24 DE NOVIEMB.1564 Comuna 3 1242
## 6 28/1/2019 A. BUFANO 2469 Comuna 11 1416
## Codigo.postal.argentino Tipo.obra Superficie..m2.
## 1 C1429BJB Obra Menor 260.72
## 2 C1429BIC Obra Media 1024.32
## 3 C1429BII Micro Obra 22.05
## 4 C1427CJR Obra Menor 253.23
## 5 C1242AAH Obra Media 1165.10
## 6 C1416AJY Obra Menor 303.16
## Direccion.normalizada Lon Lat Calle
## 1 11 DE SEPTIEMBRE DE 1888 4176 -58.46457 -34.54139 11 DE SEPTIEMBRE DE 1888
## 2 11 DE SEPTIEMBRE DE 1888 2951 -58.45760 -34.55072 11 DE SEPTIEMBRE DE 1888
## 3 11 DE SEPTIEMBRE DE 1888 3201 -58.45917 -34.54859 11 DE SEPTIEMBRE DE 1888
## 4 14 DE JULIO 882 -58.46202 -34.58321 14 DE JULIO
## 5 24 DE NOVIEMBRE 1564 -58.40986 -34.62940 24 DE NOVIEMBRE
## 6 BUFANO, ALFREDO R. 2469 -58.47767 -34.60467 BUFANO, ALFREDO R.
## Altura Barrio Comuna fecha tiempo
## 1 4176 NuĆĘƱez 13 2019-05-21 755 days
## 2 2951 NuĆĘƱez 13 2019-05-21 755 days
## 3 3201 NuĆĘƱez 13 2019-03-11 826 days
## 4 882 Villa Ortuzar 15 2019-01-03 893 days
## 5 1564 San Cristobal 3 2019-04-04 802 days
## 6 2469 Villa Del Parque 11 2019-01-28 868 days
Si dibujamos un historgrama podremos visualizar la distribución de la variable numérica que creamos
ggplot(obras_2019)+
geom_histogram(aes(x=tiempo))
## Don't know how to automatically pick scale for object of type difftime. Defaulting to continuous.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Y un poco mĆ”s en detalleā¦
ggplot(obras_2019 %>%
group_by(fecha) %>%
summarise(cantidad=n())) +
geom_line(aes(x = fecha, y = cantidad))
Enero y julio son los meses de 2019 que registraron mayor cantidad de obras
obras_2019 <- obras_2019 %>%
mutate(mes=month(fecha, label = TRUE))
head(obras_2019)
## Seccion Manzana Parcela SMP Expediente Nomenclacion.par
## 1 29 84b 21 029-84b-021 34915804/18 16-29-84b-21
## 2 27 72 11 027-072-011 18781034/18 16-27-72-11
## 3 27 75 009a 027-075-009a 19346833/18 16-27-75-009A
## 4 49 134 11 049-134-011 12279250/18 15-49-134-11
## 5 30 42 16 030-042-016 13113507/18 8-30-42-16
## 6 69 77 25 069-077-025 30348622/18 15-69-77-25
## Fecha.de.registro Direccion Comuna.1 Codigo.postal
## 1 21/5/2019 11 DE SEPT.4176 Comuna 13 1429
## 2 21/5/2019 11 DE SEPTIEMBRE 2951/57 Comuna 13 1429
## 3 11/3/2019 11 DE SEPTIEMBRE 3201/05 Comuna 13 1429
## 4 3/1/2019 14 DE JULIO 882 Comuna 15 1427
## 5 4/4/2019 24 DE NOVIEMB.1564 Comuna 3 1242
## 6 28/1/2019 A. BUFANO 2469 Comuna 11 1416
## Codigo.postal.argentino Tipo.obra Superficie..m2.
## 1 C1429BJB Obra Menor 260.72
## 2 C1429BIC Obra Media 1024.32
## 3 C1429BII Micro Obra 22.05
## 4 C1427CJR Obra Menor 253.23
## 5 C1242AAH Obra Media 1165.10
## 6 C1416AJY Obra Menor 303.16
## Direccion.normalizada Lon Lat Calle
## 1 11 DE SEPTIEMBRE DE 1888 4176 -58.46457 -34.54139 11 DE SEPTIEMBRE DE 1888
## 2 11 DE SEPTIEMBRE DE 1888 2951 -58.45760 -34.55072 11 DE SEPTIEMBRE DE 1888
## 3 11 DE SEPTIEMBRE DE 1888 3201 -58.45917 -34.54859 11 DE SEPTIEMBRE DE 1888
## 4 14 DE JULIO 882 -58.46202 -34.58321 14 DE JULIO
## 5 24 DE NOVIEMBRE 1564 -58.40986 -34.62940 24 DE NOVIEMBRE
## 6 BUFANO, ALFREDO R. 2469 -58.47767 -34.60467 BUFANO, ALFREDO R.
## Altura Barrio Comuna fecha tiempo mes
## 1 4176 NuĆĘƱez 13 2019-05-21 755 days may
## 2 2951 NuĆĘƱez 13 2019-05-21 755 days may
## 3 3201 NuĆĘƱez 13 2019-03-11 826 days mar
## 4 882 Villa Ortuzar 15 2019-01-03 893 days ene
## 5 1564 San Cristobal 3 2019-04-04 802 days abr
## 6 2469 Villa Del Parque 11 2019-01-28 868 days ene
Luego de agrupar los datos en una variable mensual, volvemos a graficar
ggplot(obras_2019) +
geom_bar(aes(x = mes))
Se puede observar, una vez mas, que en enero y en julio se registraron la mayor cantidad de obras en 2019 y que bajaron considerablemente en los últimos tres meses del año.
ggplot(obras_2019) +
geom_bar(aes(x = mes, fill=Tipo.obra)) +
labs(title = "Obras registradas en la Ciudad de Buenos Aires",
subtitle = "AƱo 2019",
x = "Mes",
y = "Cantidad",
fill = "Tipo de Obra",
caption = "Fuente: BA Data")
ggplot(obras_2019) +
geom_bar(aes(x = mes, fill=Tipo.obra), position = "dodge") +
labs(title = "Obras registradas en la Ciudad de Buenos Aires",
subtitle = "AƱo 2019",
x = "Mes",
y = "Cantidad",
fill = "Tipo de Obra",
caption = "Fuente: BA Data")
ggplot(obras_2019 %>%
group_by(mes, Tipo.obra) %>%
summarise(cantidad = n())) +
geom_line(aes(x = mes, y = cantidad, color=Tipo.obra, group=Tipo.obra)) +
labs(title = "Obras registradas en la Ciudad de Buenos Aires",
subtitle = "AƱo 2019",
x = "Mes",
y = "Cantidad",
color = "Tipo de Obra",
caption = "Fuente: BA Data")
## `summarise()` has grouped output by 'mes'. You can override using the `.groups` argument.
En unos de los meses de mayor registro (julio) el porcentaje de obras mayores es significativamente superior al resto de la sobras que bajaron en comparación al resto del año.
ggplot(obras_2019 %>%
group_by(mes, Tipo.obra) %>%
summarise(cantidad = n())) +
geom_line(aes(x = mes, y = cantidad, color=Tipo.obra, group=Tipo.obra)) +
geom_text(aes(x=mes, y=cantidad+200, label=cantidad), size=2.5)+
labs(title = "Obras registradas en la Ciudad de Buenos Aires",
subtitle = "AƱo 2019",
x = "Mes",
y = "Cantidad",
color = "Tipo de Obra",
caption = "Fuente: BA Data")
## `summarise()` has grouped output by 'mes'. You can override using the `.groups` argument.
Hagamos un Zoom a āObra Menorā
ggplot(obras_2019 %>%
filter(Tipo.obra == "Obra Menor") %>%
group_by(mes, Tipo.obra) %>%
summarise(cantidad = n())) +
geom_line(aes(x = mes, y = cantidad, group = Tipo.obra, color = Tipo.obra), size=1) +
geom_point(aes(x=mes, y=cantidad, color = Tipo.obra), size=2)+
labs(title = "Obras registradas en la Ciudad de Buenos Aires",
subtitle = "AƱo 2019",
x = "Mes",
y = "Cantidad",
color = "Tipo de Obra",
caption = "Fuente: BA Data")
## `summarise()` has grouped output by 'mes'. You can override using the `.groups` argument.
Si bien julio es uno d elos meses con mayor obras registradas, las obras menores son muy escasas.
obras_2019 <- obras_2019 %>%
mutate(dia_semana=wday(fecha, label = TRUE))
head(obras_2019)
## Seccion Manzana Parcela SMP Expediente Nomenclacion.par
## 1 29 84b 21 029-84b-021 34915804/18 16-29-84b-21
## 2 27 72 11 027-072-011 18781034/18 16-27-72-11
## 3 27 75 009a 027-075-009a 19346833/18 16-27-75-009A
## 4 49 134 11 049-134-011 12279250/18 15-49-134-11
## 5 30 42 16 030-042-016 13113507/18 8-30-42-16
## 6 69 77 25 069-077-025 30348622/18 15-69-77-25
## Fecha.de.registro Direccion Comuna.1 Codigo.postal
## 1 21/5/2019 11 DE SEPT.4176 Comuna 13 1429
## 2 21/5/2019 11 DE SEPTIEMBRE 2951/57 Comuna 13 1429
## 3 11/3/2019 11 DE SEPTIEMBRE 3201/05 Comuna 13 1429
## 4 3/1/2019 14 DE JULIO 882 Comuna 15 1427
## 5 4/4/2019 24 DE NOVIEMB.1564 Comuna 3 1242
## 6 28/1/2019 A. BUFANO 2469 Comuna 11 1416
## Codigo.postal.argentino Tipo.obra Superficie..m2.
## 1 C1429BJB Obra Menor 260.72
## 2 C1429BIC Obra Media 1024.32
## 3 C1429BII Micro Obra 22.05
## 4 C1427CJR Obra Menor 253.23
## 5 C1242AAH Obra Media 1165.10
## 6 C1416AJY Obra Menor 303.16
## Direccion.normalizada Lon Lat Calle
## 1 11 DE SEPTIEMBRE DE 1888 4176 -58.46457 -34.54139 11 DE SEPTIEMBRE DE 1888
## 2 11 DE SEPTIEMBRE DE 1888 2951 -58.45760 -34.55072 11 DE SEPTIEMBRE DE 1888
## 3 11 DE SEPTIEMBRE DE 1888 3201 -58.45917 -34.54859 11 DE SEPTIEMBRE DE 1888
## 4 14 DE JULIO 882 -58.46202 -34.58321 14 DE JULIO
## 5 24 DE NOVIEMBRE 1564 -58.40986 -34.62940 24 DE NOVIEMBRE
## 6 BUFANO, ALFREDO R. 2469 -58.47767 -34.60467 BUFANO, ALFREDO R.
## Altura Barrio Comuna fecha tiempo mes dia_semana
## 1 4176 NuĆĘƱez 13 2019-05-21 755 days may mar\\.
## 2 2951 NuĆĘƱez 13 2019-05-21 755 days may mar\\.
## 3 3201 NuĆĘƱez 13 2019-03-11 826 days mar lun\\.
## 4 882 Villa Ortuzar 15 2019-01-03 893 days ene jue\\.
## 5 1564 San Cristobal 3 2019-04-04 802 days abr jue\\.
## 6 2469 Villa Del Parque 11 2019-01-28 868 days ene lun\\.
ggplot(obras_2019) +
geom_bar(aes(x = dia_semana))
ggplot(obras_2019) +
geom_bar(aes(x = dia_semana, fill=Tipo.obra))
El jueves es el dĆa de la semana con mayor registro de obras en 2019.
ggplot(obras_2019) +
geom_bar(aes(x = dia_semana, fill=Tipo.obra), position = "dodge")
ggplot(obras_2019 %>%
group_by(Tipo.obra, dia_semana) %>%
summarise(cantidad=n())) +
geom_line(aes(x = dia_semana, y=cantidad, group = Tipo.obra, color = Tipo.obra), size=1) +
geom_point(aes(x = dia_semana, y=cantidad, color = Tipo.obra), size=2)+
geom_text(aes(x = dia_semana, y=cantidad+200, label=cantidad), size=2)+
labs(title = "Obras registradas en la Ciudad de Buenos Aires",
subtitle = "AƱo 2019",
x = "DĆa de la Semana",
y = "Cantidad",
color = "Tipo de Obra",
caption = "Fuente: BA Data")
## `summarise()` has grouped output by 'Tipo.obra'. You can override using the `.groups` argument.
NO SE PUEDE BUSCAR UN PATRĆN POR HORA YA QUE EL DATO NO ESTĆ REGISTRADO EN ESTE DATA SET
ANĆLISIS ESPACIAL
bbox <- make_bbox(obras_2019$Lon, obras_2019$Lat)
mapa_base <- get_stamenmap(bbox = bbox,
maptype = "toner-lite",
zoom = 12)
## Source : http://tile.stamen.com/toner-lite/12/1381/2467.png
## Source : http://tile.stamen.com/toner-lite/12/1382/2467.png
## Source : http://tile.stamen.com/toner-lite/12/1383/2467.png
## Source : http://tile.stamen.com/toner-lite/12/1384/2467.png
## Source : http://tile.stamen.com/toner-lite/12/1381/2468.png
## Source : http://tile.stamen.com/toner-lite/12/1382/2468.png
## Source : http://tile.stamen.com/toner-lite/12/1383/2468.png
## Source : http://tile.stamen.com/toner-lite/12/1384/2468.png
## Source : http://tile.stamen.com/toner-lite/12/1381/2469.png
## Source : http://tile.stamen.com/toner-lite/12/1382/2469.png
## Source : http://tile.stamen.com/toner-lite/12/1383/2469.png
## Source : http://tile.stamen.com/toner-lite/12/1384/2469.png
ggmap(mapa_base)
ggmap(mapa_base) +
geom_point(data = obras_2019, aes(x = Lon, y = Lat))
ggmap(mapa_base) +
geom_point(data = obras_2019, aes(x = Lon, y = Lat, color=Tipo.obra), alpha=0.8)
ggmap(mapa_base) +
geom_point(data = obras_2019, aes(x = Lon, y = Lat, color=Tipo.obra), alpha=0.6)+
facet_wrap(~Tipo.obra)
ggmap(mapa_base) +
geom_bin2d(data = obras_2019,
aes(x = Lon, y = Lat))
ggmap(mapa_base) +
geom_bin2d(data = obras_2019,
aes(x = Lon, y = Lat), bins=50)+
scale_fill_viridis_c(option = "magma", direction=-1)
Podemos observar que el corredor norte de la Ciudad y la zona de Flores, Parque Avellaneda y Parque Chacabuco concentraron la mayor cantidad de obras en 2019.
ggmap(mapa_base) +
geom_bin2d(data = obras_2019,
aes(x = Lon, y = Lat), bins=50)+
scale_fill_viridis_c(direction=-1)+
facet_wrap(~Tipo.obra)
ANĆLISIS TEMPORAL Y ESPACIAL
ggmap(mapa_base) +
geom_bin2d(data = obras_2019,
aes(x = Lon, y = Lat))+
scale_fill_viridis_c(direction=-1)+
facet_wrap(~dia_semana)
Pareciera que el lunes es el dĆa hĆ”bil en el que menos se registraron obras en CABA en el mismo aƱo
ggmap(mapa_base) +
geom_bin2d(data = obras_2019,
aes(x = Lon, y = Lat))+
scale_fill_viridis_c(direction=-1)+
facet_wrap(~mes)
Este grÔfico nos muestra que julio es el mes de 2019 en el que mÔs se registraron obras, mientras que se evidencia una fuerte caida en el último trimestre del año.
ggmap(mapa_base) +
stat_density_2d(data = obras_2019,
aes(x = Lon, y = Lat,
fill = stat(level)), alpha = 0.8, geom = "polygon") +
labs(title="Obras registradas en la Ciudad de Buenos Aires",
subtitle="AƱo 2019",
caption= "Fuente de datos: https://data.buenosaires.gob.ar/",
fill="Nivel")+
theme_void()+
scale_fill_distiller(palette = "Spectral")
Finalmente, podemos concluir que el mapa de calor graficado, refuerza lo arrojado por los anteriores en relación a las zonas de CABA que registraron mayor cantidad de obras registradas durante 2019.