Antes de iniciar el analisis del dataset operativos en CABA voy a activar las librerias a utilizar.
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.0.5
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.2 v dplyr 1.0.7
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## Warning: package 'ggplot2' was built under R version 4.0.5
## Warning: package 'tibble' was built under R version 4.0.5
## Warning: package 'dplyr' was built under R version 4.0.5
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(sf)
## Warning: package 'sf' was built under R version 4.0.5
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(ggmap)
## Warning: package 'ggmap' was built under R version 4.0.5
## 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)
## Warning: package 'lubridate' was built under R version 4.0.5
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
Voy a leer el dataset y visualizar con summary el contenido del mismo.
operativos2018 <- read.csv("operativos-2018.csv", stringsAsFactors = TRUE)
summary(operativos2018)
## long lat fecha
## Min. :-58.53 Min. :-34.70 2018-12-13: 119
## 1st Qu.:-58.47 1st Qu.:-34.64 2018-12-30: 115
## Median :-58.43 Median :-34.63 2018-12-14: 79
## Mean :-58.43 Mean :-34.63 2018-05-10: 70
## 3rd Qu.:-58.39 3rd Qu.:-34.61 2018-05-02: 69
## Max. :-58.34 Max. :-34.53 2018-08-09: 69
## (Other) :9384
## suceso
## ARBOLES / RAMAS :1830
## PELIGRO DE CAIDA COLUMNA / POSTE / CARTEL / LUMINARIA:1268
## CABLES EXPUESTOS / CAIDOS :1164
## ESCAPE DE GAS :1067
## RIESGO ELECTRICO : 661
## INCENDIO : 548
## (Other) :3367
## calle_nombre calle_altura barrio
## RIVADAVIA : 185 Min. : 0 BALVANERA : 674
## ALBERDI JUAN BAUTISTA AV: 65 1st Qu.: 0 FLORES : 673
## INDEPENDENCIA AV : 63 Median : 1038 BARRACAS : 595
## SAN JUAN : 53 Mean : 1683 VILLA LUGANO: 579
## CORRIENTES : 50 3rd Qu.: 2671 CABALLITO : 547
## FALCON RAMON L.CNEL. : 48 Max. :16100 MATADEROS : 425
## (Other) :9441 (Other) :6412
## comuna observacion movil
## COMUNA 4:1645 :3764 Min. : 0
## COMUNA 1:1324 S/NOVEDAD : 596 1st Qu.: 140
## COMUNA 9:1000 SIN NOVEDAD : 511 Median : 303
## COMUNA 7: 997 SE SEĆāALIZA SE PASA AL CUCC: 210 Mean : 393
## COMUNA 8: 985 SE PASA AL CUCC : 142 3rd Qu.: 797
## COMUNA 3: 928 S/ NOVEDAD : 135 Max. :8550
## (Other) :3026 (Other) :4547
## a_cargo turno emergencia prevencion
## ALARCON: 431 : 112 no: 413 no:9492
## BERARDI: 316 F/S:2060 si:9492 si: 413
## CASCO : 301 TM :2842
## SANZ : 264 TN :2178
## LIO : 257 TT :2713
## ENRIQUE: 249
## (Other):8087
## amenaza mes
## OTROS :5902 DICIEMBRE:1167
## 13) INTERRUPCION DE SERVICIOS BASICOS :1528 AGOSTO : 959
## 7) FUGA DE GAS : 671 ENERO : 944
## 14) INTOXICACIONES Y CONTAMINACIONES : 541 NOVIEMBRE: 865
## 1) LLUVIAS TORRENCIALES Y FUERTES VIENTOS: 419 MAYO : 853
## 3) INCENDIOS : 414 ABRIL : 770
## (Other) : 430 (Other) :4347
## codigo_postal codigo_postal_argentino
## Min. :1001 :2889
## 1st Qu.:1199 C1405CVH: 20
## Median :1406 C1160ACD: 14
## Mean :1311 C1272ADF: 12
## 3rd Qu.:1425 C1416DGM: 12
## Max. :1440 C1282AFF: 10
## NA's :2883 (Other) :6948
wday(today(), label = TRUE, abbr = FALSE)
## [1] sƔbado
## 7 Levels: domingo < lunes < martes < miƩrcoles < jueves < ... < sƔbado
Ahora voy a transformar el dataset para que figure el dĆa de la semana de los operativos.
operativos2018 <- operativos2018 %>%
mutate(fecha=ymd(fecha))
Como anteriormente aparecia el nĆŗmero de la semana vamos a configurar para que aparezca el dĆa de la semana sin abreviaturas.
operativos2018 <- operativos2018 %>%
mutate(dia_semana=wday(fecha, label = TRUE, abbr = FALSE))
Ahora vamos a ver si ya nos figura la fecha.
str(operativos2018)
## 'data.frame': 9905 obs. of 19 variables:
## $ long : num -58.5 -58.4 -58.4 -58.5 -58.5 ...
## $ lat : num -34.7 -34.6 -34.6 -34.6 -34.6 ...
## $ fecha : Date, format: "2018-01-01" "2018-01-01" ...
## $ suceso : Factor w/ 46 levels "","ACCIDENTE",..: 9 8 9 28 28 28 28 28 28 28 ...
## $ calle_nombre : Factor w/ 3108 levels "","11 DE SEPTIEMBRE DE 1888",..: 648 90 2746 454 770 1306 1344 202 1462 621 ...
## $ calle_altura : int 2080 0 0 2566 74 1723 1150 672 335 674 ...
## $ barrio : Factor w/ 48 levels "AGRONOMIA","ALMAGRO",..: 16 8 23 13 14 8 13 8 13 8 ...
## $ comuna : Factor w/ 15 levels "COMUNA 1","COMUNA 10",..: 15 12 13 13 2 12 13 12 13 12 ...
## $ observacion : Factor w/ 2760 levels "","(NO SE CONCURRE) SE SOLICITA CONTROL AMBIENTAL",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ movil : num 157 855 140 371 371 371 371 371 371 371 ...
## $ a_cargo : Factor w/ 538 levels "","ACR","ACRI",..: 468 414 326 336 336 336 336 336 336 336 ...
## $ turno : Factor w/ 5 levels "","F/S","TM",..: 2 2 2 2 2 2 2 2 2 2 ...
## $ emergencia : Factor w/ 2 levels "no","si": 2 2 2 2 2 2 2 2 2 2 ...
## $ prevencion : Factor w/ 2 levels "no","si": 1 1 1 1 1 1 1 1 1 1 ...
## $ amenaza : Factor w/ 14 levels "1) LLUVIAS TORRENCIALES Y FUERTES VIENTOS",..: 14 4 14 3 3 3 3 3 3 3 ...
## $ mes : Factor w/ 12 levels "ABRIL","AGOSTO",..: 4 4 4 4 4 4 4 4 4 4 ...
## $ codigo_postal : int 1440 NA NA 1406 1407 1416 1406 1405 1406 1405 ...
## $ codigo_postal_argentino: Factor w/ 5098 levels "","C1001AAB",..: 5067 1 1 2523 2621 3330 2185 2130 2167 2087 ...
## $ dia_semana : Ord.factor w/ 7 levels "domingo"<"lunes"<..: 2 2 2 2 2 2 2 2 2 2 ...
Ya tenemos el dataset listo para poder analizar en cuanto a la temporalidad de los operativos y las ubicaciones geogrƔficas.
En el siguiente grafico se visualiza por mes la cantidad de operativos distinguiendo el mes de diciembre con casi 1.200 operativos en el mes, siguiendo por el mes de agosto con mÔs de 1.000. Este patrón nos deja detectar los meses con mayores y con menores operativos.
ggplot(operativos2018)+
geom_bar(aes(x=mes))
Ahora realice el analisis por dĆa de semana para ver si se puede identificar algĆŗn patron.
ggplot(operativos2018)+
geom_bar(aes(x=dia_semana))
Los jueves son los dĆas mas recurrentes para los operativos. Ahora voy a analizar por comuna para distinguir si hay alguna con mayor concentración.
ggplot(operativos2018 %>%
group_by(mes,comuna) %>%
summarise(cantidad=n()))+
geom_line(aes(x=mes, y=cantidad, color=comuna, group=comuna))
## `summarise()` has grouped output by 'mes'. You can override using the `.groups` argument.
Hasta ahora analice la temporalidad de los operativos. Ahora la idea es utilizar tambien el analisis espacial.
Primero para esto vamos a usar de base el mapa de la Ciudad.
bbox <- make_bbox(operativos2018$long, operativos2018$lat)
mapa_base <- get_stamenmap(bbox = bbox,
maptype = "toner-lite",
zoom = 12)
## Source : http://tile.stamen.com/toner-lite/12/1381/2466.png
## Source : http://tile.stamen.com/toner-lite/12/1382/2466.png
## Source : http://tile.stamen.com/toner-lite/12/1383/2466.png
## Source : http://tile.stamen.com/toner-lite/12/1384/2466.png
## 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)
Voy a mapear las ubicaciones de los operativos en el dataset.
ggmap(mapa_base) +
geom_point(data = operativos2018, aes(x = long, y = lat),
color = "orange", size = 0.1, alpha = 0.1)
Aoy a identificar la densidad para ver si se puede observar un patron espacial,es decir, acumulación de puntos, que permite bien en que lugar de la ciudad hay mayor operaciones.
ggmap(mapa_base) +
geom_bin2d(data = operativos2018,
aes(x = long, y = lat))
Para poder observarlo con mas claridad agregamos transparencia para analizar el patron con mas detalle.
ggmap(mapa_base) +
geom_bin2d(data = operativos2018, aes(x = long, y = lat), bins = 50) +
scale_fill_viridis_c()
Combinando el analisis espacial y temporal.
Se puede distinguir si hay un dĆa por sobre otro con mayor carga de operativos en CABA de manera espacial.
ggmap(mapa_base) +
geom_bin2d(data = operativos2018, aes(x = long, y = lat), alpha=0.8, bins = 50) +
scale_fill_viridis_c()+
facet_wrap(~dia_semana)