Gonzalo Slides

GHCq9

Carga de datos

load("datos/accidentes2020_data.rda")
library(tidyverse)
accidentes_tb <- 
  accidentes2020_data |> 
  as_tibble()
accidentes_tb
# A tibble: 32,427 × 17
   num_expediente fecha      hora    localizacion numero distrito tipo_accidente
   <chr>          <chr>      <chr>   <chr>        <chr>  <chr>    <chr>         
 1 2019S040008    07/09/2020 23:00:… CALL. SAN M… 38     CIUDAD … Choque contra…
 2 2019S040008    07/09/2020 23:00:… CALL. SAN M… 38     CIUDAD … Choque contra…
 3 2020S000001    01/01/2020 1:15:00 AVDA. CANIL… 1      SAN BLA… Colisión fron…
 4 2020S000001    01/01/2020 1:15:00 AVDA. CANIL… 1      SAN BLA… Colisión fron…
 5 2020S000002    01/01/2020 1:20:00 CALL. SILVA… 31     HORTALE… Choque contra…
 6 2020S000002    01/01/2020 1:20:00 CALL. SILVA… 31     HORTALE… Choque contra…
 7 2020S000003    01/01/2020 2:00:00 CALL. BRAVO… 1      CHAMBERÍ Alcance       
 8 2020S000003    01/01/2020 2:00:00 CALL. BRAVO… 1      CHAMBERÍ Alcance       
 9 2020S000003    01/01/2020 2:00:00 CALL. BRAVO… 1      CHAMBERÍ Alcance       
10 2020S000004    01/01/2020 1:00:00 CALL. MANDA… 5      CIUDAD … Choque contra…
# ℹ 32,417 more rows
# ℹ 10 more variables: estado_meteorológico <chr>, tipo_vehiculo <chr>,
#   tipo_persona <chr>, rango_edad <chr>, sexo <chr>, lesividad <chr>,
#   coordenada_x_utm <dbl>, coordenada_y_utm <dbl>, positiva_alcohol <chr>,
#   positiva_droga <chr>

Resumen

resumen <- accidentes_tb |> 
  count(distrito)
resumen
# A tibble: 22 × 2
   distrito                n
   <chr>               <int>
 1 ARGANZUELA           1351
 2 BARAJAS               545
 3 CARABANCHEL          2076
 4 CENTRO               1518
 5 CHAMARTÍN            2084
 6 CHAMBERÍ             1491
 7 CIUDAD LINEAL        2127
 8 FUENCARRAL-EL PARDO  1786
 9 HORTALEZA            1508
10 LATINA               1505
# ℹ 12 more rows

Visualización

ggplot(resumen) +
  geom_col(aes(x = distrito, y = n, fill = distrito), alpha = 0.6) +
  labs(title = "Accidentes por distrito",
       x = "Distrito",
       y = "Cantidad") +
  ggthemes::scale_fill_colorblind() +
  theme_minimal()