Realizar 2 gráficos que les permitan analizar la temporalidad de los datos.¿Detectan algún patrón temporal? ¿A qué puede deberse?
Analizar la distribución espacial de los datos a partir de:
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(lubridate)
## Warning: package 'lubridate' was built under R version 3.6.1
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
operativos.2018 <- read.csv("~/MEU/MU115 - CIencia de Datos II/operativos-2018.csv")
names(operativos.2018)
## [1] "long" "lat"
## [3] "fecha" "suceso"
## [5] "calle_nombre" "calle_altura"
## [7] "barrio" "comuna"
## [9] "observacion" "movil"
## [11] "a_cargo" "turno"
## [13] "emergencia" "prevencion"
## [15] "amenaza" "mes"
## [17] "codigo_postal" "codigo_postal_argentino"
summary(operativos.2018)
## 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
operativos.2018 <- operativos.2018 %>%
mutate(fecha=ymd(fecha))
set.seed("99")
muestra_de_fechas <- operativos.2018 %>%
sample_n(5) %>%
pull(fecha)
muestra_de_fechas
## [1] "2018-08-03" "2018-10-13" "2018-03-26" "2018-04-21" "2018-09-30"
operativos.2018 %>%
filter(year(fecha) == 2018) %>%
ggplot() +
geom_bar(aes(x = month(fecha, label = TRUE)))
Lo graficamos por tipo de operativo:
operativos.2018 %>%
count(suceso) %>%
top_n(5) %>%
arrange(desc(n))
## Selecting by n
## # A tibble: 5 x 2
## suceso n
## <fct> <int>
## 1 ARBOLES / RAMAS 1830
## 2 PELIGRO DE CAIDA COLUMNA / POSTE / CARTEL / LUMINARIA 1268
## 3 CABLES EXPUESTOS / CAIDOS 1164
## 4 ESCAPE DE GAS 1067
## 5 RIESGO ELECTRICO 661
operativos_frecuentes <- operativos.2018 %>%
count(suceso) %>%
top_n(5) %>%
pull(suceso)
## Selecting by n
operativos.2018 %>%
filter(year(fecha) == 2018,
suceso %in% operativos_frecuentes) %>%
ggplot() +
geom_bar(aes(x = month(fecha, label = TRUE), fill = suceso))
operativos.2018 %>%
filter(year(fecha) == 2018,
suceso %in% operativos_frecuentes) %>%
ggplot() +
geom_bar(aes(x = month(fecha, label = TRUE), fill = suceso),
position = "dodge")
El suceso mas comun es la caida de ramas y arboles, en los meses de Enero, Noviembre y la mayoria se produjo en Diciembre. Supongo que el patron temporal de dicah distribucion tendra que ver con las lluvias que cayeron en la ciudad, seguramente han sido mas copiosas en esos meses de verano. La mayor cantidad de operativos en relacion a escapes de gas se dieron en el mes de Agosto, epoca invernal.
operativos.2018 %>%
count(a_cargo) %>%
top_n(5) %>%
arrange(desc(n))
## Selecting by n
## # A tibble: 5 x 2
## a_cargo n
## <fct> <int>
## 1 ALARCON 431
## 2 BERARDI 316
## 3 CASCO 301
## 4 SANZ 264
## 5 LIO 257
operativos_agentes <- operativos.2018 %>%
count(a_cargo) %>%
top_n(5) %>%
pull(a_cargo)
## Selecting by n
operativos.2018 %>%
filter(year(fecha) == 2018,
a_cargo %in% operativos_agentes) %>%
ggplot() +
geom_bar(aes(x = month(fecha, label = TRUE), fill = a_cargo))
operativos.2018 %>%
filter(year(fecha) == 2018,
a_cargo %in% operativos_agentes) %>%
ggplot() +
geom_bar(aes(x = month(fecha, label = TRUE), fill = a_cargo),
position = "dodge")
conteo_operativos <- operativos.2018 %>%
filter(year(fecha) == 2018,
suceso %in% operativos_frecuentes) %>%
count(suceso, mes = month(fecha, label = TRUE))
ggplot(conteo_operativos) +
geom_line(aes(x = mes, y = n, group = suceso, color = suceso))+
geom_point(aes(x = mes, y = n, group = suceso, color = suceso, size = 0.05))+
scale_color_brewer(palette = "set1")+
labs(title="Top 5 de operativos 2018",
color="tipo de operativo",
x="meses",
y = "Cantidad")+
theme_minimal()
## Warning in pal_name(palette, type): Unknown palette set1
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.
operativos.2018 <- operativos.2018 %>%
filter(lat <0, long <0)
bbox <- c(min(operativos.2018$long, na.rm = TRUE),
min(operativos.2018$lat, na.rm = TRUE),
max(operativos.2018$long, na.rm = TRUE),
max(operativos.2018$lat, na.rm = TRUE))
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
bbox <- getbb("Ciudad Autonoma de Buenos Aires")
bbox
## min max
## x -58.53146 -58.33512
## y -34.70564 -34.52655
CABA <- get_stamenmap(bbox = bbox,
maptype="toner-lite",
zoom=13)
## Source : http://tile.stamen.com/toner-lite/13/2764/4934.png
## Source : http://tile.stamen.com/toner-lite/13/2765/4934.png
## Source : http://tile.stamen.com/toner-lite/13/2766/4934.png
## Source : http://tile.stamen.com/toner-lite/13/2767/4934.png
## Source : http://tile.stamen.com/toner-lite/13/2768/4934.png
## Source : http://tile.stamen.com/toner-lite/13/2764/4935.png
## Source : http://tile.stamen.com/toner-lite/13/2765/4935.png
## Source : http://tile.stamen.com/toner-lite/13/2766/4935.png
## Source : http://tile.stamen.com/toner-lite/13/2767/4935.png
## Source : http://tile.stamen.com/toner-lite/13/2768/4935.png
## Source : http://tile.stamen.com/toner-lite/13/2764/4936.png
## Source : http://tile.stamen.com/toner-lite/13/2765/4936.png
## Source : http://tile.stamen.com/toner-lite/13/2766/4936.png
## Source : http://tile.stamen.com/toner-lite/13/2767/4936.png
## Source : http://tile.stamen.com/toner-lite/13/2768/4936.png
## Source : http://tile.stamen.com/toner-lite/13/2764/4937.png
## Source : http://tile.stamen.com/toner-lite/13/2765/4937.png
## Source : http://tile.stamen.com/toner-lite/13/2766/4937.png
## Source : http://tile.stamen.com/toner-lite/13/2767/4937.png
## Source : http://tile.stamen.com/toner-lite/13/2768/4937.png
## Source : http://tile.stamen.com/toner-lite/13/2764/4938.png
## Source : http://tile.stamen.com/toner-lite/13/2765/4938.png
## Source : http://tile.stamen.com/toner-lite/13/2766/4938.png
## Source : http://tile.stamen.com/toner-lite/13/2767/4938.png
## Source : http://tile.stamen.com/toner-lite/13/2768/4938.png
## Source : http://tile.stamen.com/toner-lite/13/2764/4939.png
## Source : http://tile.stamen.com/toner-lite/13/2765/4939.png
## Source : http://tile.stamen.com/toner-lite/13/2766/4939.png
## Source : http://tile.stamen.com/toner-lite/13/2767/4939.png
## Source : http://tile.stamen.com/toner-lite/13/2768/4939.png
ggmap(CABA)
ggmap(CABA) +
geom_point(data = operativos.2018, aes(x = long, y = lat),
color = "green", size = 0.5, alpha = 0.1)
ggmap(CABA) +
geom_bin2d(data = operativos.2018,
aes(x = long, y = lat), bins=75)+
scale_fill_viridis_c()
ggmap(CABA) +
geom_density2d(data = operativos.2018, aes(x = long, y = lat, color = stat(level))) +
scale_color_viridis_c()
ggmap(CABA) +
geom_point(data = filter(operativos.2018, suceso %in% operativos_frecuentes),
aes(x = long, y = lat, color = suceso),
size = 0.5, alpha = 0.1) +
guides(color = guide_legend(override.aes = list(size=2, alpha = 1))) +
scale_color_brewer(palette = "Set1")
ggmap(CABA) +
geom_point(data = filter(operativos.2018, suceso %in% operativos_frecuentes),
aes(x = long, y = lat, color = suceso),
size = 0.5, alpha = 0.1) +
guides(color = guide_legend(override.aes = list(size=2, alpha = 1))) +
scale_color_brewer(palette = "Set1") +
facet_wrap(~suceso)
ggmap(CABA) +
geom_density2d(data = filter(operativos.2018, suceso %in% operativos_frecuentes), aes(x = long, y = lat, color = stat(level))) +
scale_color_viridis_c() +
facet_wrap(~suceso)
operativos.2018 <- operativos.2018 %>%
mutate(dia=wday(fecha, label=TRUE))
ggmap(CABA) +
geom_density2d(data = filter(operativos.2018, suceso %in% operativos_frecuentes), aes(x = long, y = lat, color = stat(level))) +
scale_color_viridis_c() +
facet_wrap(~dia, nrow=2)