# Accidentalidad Motos Medellín 2015-2020
library(janitor)
## Warning: package 'janitor' was built under R version 4.0.3
##
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
library(tidyverse)
## -- Attaching packages ---------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2 v purrr 0.3.4
## v tibble 3.0.3 v dplyr 1.0.2
## v tidyr 1.1.2 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.0
## -- Conflicts ------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(Hmisc)
## Warning: package 'Hmisc' was built under R version 4.0.3
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Warning: package 'Formula' was built under R version 4.0.3
##
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:dplyr':
##
## src, summarize
## The following objects are masked from 'package:base':
##
## format.pval, units
data_motos <- read_csv("Accidentalidad_con_motos_municipio_de_Medell_n_a_o_2019.csv") %>%
clean_names() %>%
mutate(fecha_accidente = as.Date(fecha_accidente, format = "%m/%d/%Y")) %>%
mutate_if(is.character, tolower) %>%
mutate_if(is.character, capitalize) %>%
mutate_if(is.character, as.factor)
##
## -- Column specification ---------------------------------------------------
## cols(
## RADICADO = col_double(),
## AÑO_ACCIDENTE = col_double(),
## FECHA_ACCIDENTE = col_character(),
## HORA_ACCIDENTE = col_time(format = ""),
## CLASE_ACCIDENTE = col_character(),
## GRAVEDAD_ACCIDENTE = col_character(),
## DIRECCION = col_character(),
## ZONA = col_character(),
## `Diseño Vía` = col_character()
## )
## Warning: 97093 parsing failures.
## row col expected actual file
## 4078 HORA_ACCIDENTE time like 1899-12-31T01:10:00.000 'Accidentalidad_con_motos_municipio_de_Medell_n_a_o_2019.csv'
## 4079 HORA_ACCIDENTE time like 1899-12-31T01:10:00.000 'Accidentalidad_con_motos_municipio_de_Medell_n_a_o_2019.csv'
## 4080 HORA_ACCIDENTE time like 1899-12-31T01:50:00.000 'Accidentalidad_con_motos_municipio_de_Medell_n_a_o_2019.csv'
## 4081 HORA_ACCIDENTE time like 1899-12-31T01:45:00.000 'Accidentalidad_con_motos_municipio_de_Medell_n_a_o_2019.csv'
## 4082 HORA_ACCIDENTE time like 1899-12-31T02:00:00.000 'Accidentalidad_con_motos_municipio_de_Medell_n_a_o_2019.csv'
## .... .............. .......... ....................... .............................................................
## See problems(...) for more details.
head(data_motos)
-Consulta: ¿En cuál de las comunas (16 en total) de Medellín se presenta mayor número de accidentes?
data_motos %>%
filter( zona %in% c( "Comuna 1", "Comuna 2", "Comuna 3", "Comuna 4", "Comuna 5")) %>%
group_by(zona) %>%
summarise( total = n()) %>%
ggplot(mapping = aes(x= reorder(zona, total),
y= total))+
geom_col(fill = "red3")+
coord_flip()+
labs( x = "comuna",
y = " accidentalidad en medellin"
)
## `summarise()` ungrouping output (override with `.groups` argument)
data_motos %>%
group_by( hora_accidente) %>%
count(name = "total") %>%
ggplot(mapping = aes(x = hora_accidente, y = total)) +
geom_smooth(se = FALSE) +
labs(x = "total",
y = "hora",
title = "accidentes en moto hora")
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
data_motos %>%
filter(zona %in% c("Comuna 1", "Comuna 2", "Comuna 3", "Comuna 4", "Comuna 5", "Comuna 6", "Comuna 7", "Comuna 8", "Comuna 9", "Comuna 10", "Comuna 11", "Comuna 12", "Comuna 13", "Comuna 14", "Comuna 15", "Comuna 16")) %>%
group_by( hora_accidente,zona) %>%
count(name = "total") %>%
ggplot(mapping = aes(x = hora_accidente, y = total)) +
geom_smooth(se = FALSE) +
facet_wrap(facets = ~zona, scales = "free" , ncol = 4)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 16 rows containing non-finite values (stat_smooth).
labs(x = "total",
y = "hora",
title = "accidentes en moto hora")
## $x
## [1] "total"
##
## $y
## [1] "hora"
##
## $title
## [1] "accidentes en moto hora"
##
## attr(,"class")
## [1] "labels"