radar-summary.R 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env Rscript
  2. library(tidyverse)
  3. complete <- read_csv2("../app/data/completo.csv", na = "NA",
  4. col_types = cols(
  5. pais = col_character(),
  6. regiao = col_character(),
  7. uf = col_character(),
  8. mesorregiao = col_character(),
  9. microrregiao = col_character(),
  10. municipio = col_character(),
  11. st_acidente_feriado = col_character(),
  12. ds_agente_causador = col_character(),
  13. ano_cat = col_integer(),
  14. ds_cnae_classe_cat = col_character(),
  15. dt_acidente = col_date(),
  16. st_dia_semana_acidente = col_character(),
  17. ds_emitente_cat = col_character(),
  18. hora_acidente = col_time(),
  19. idade_cat = col_integer(),
  20. cd_indica_obito = col_character(),
  21. ds_natureza_lesao = col_character(),
  22. ds_cbo = col_character(),
  23. ds_parte_corpo_atingida = col_character(),
  24. cd_tipo_sexo_empregado_cat = col_character(),
  25. ds_tipo_acidente = col_character(),
  26. ds_tipo_local_acidente = col_character()
  27. ))
  28. #Summarization of the number of accidents occurred by year 2012-2016
  29. mun_by_year <- complete %>%
  30. group_by(uf, municipio) %>%
  31. count(ano_cat) %>%
  32. ungroup() %>%
  33. select(municipio, ano_cat, n)
  34. micro_by_year <- complete %>%
  35. group_by(microrregiao) %>%
  36. count(ano_cat) %>%
  37. ungroup() %>%
  38. select(microrregiao, ano_cat, n)
  39. meso_by_year <- complete %>%
  40. group_by(mesorregiao) %>%
  41. count(ano_cat) %>%
  42. ungroup() %>%
  43. select(mesorregiao, ano_cat, n)
  44. uf_by_year <- complete %>%
  45. group_by(uf) %>%
  46. count(ano_cat) %>%
  47. ungroup() %>%
  48. select(uf, ano_cat, n)
  49. regiao_by_year <- complete %>%
  50. group_by(regiao) %>%
  51. count(ano_cat) %>%
  52. ungroup() %>%
  53. select(regiao, ano_cat, n)
  54. pais_by_year <- complete %>%
  55. group_by(pais) %>%
  56. count(ano_cat) %>%
  57. ungroup() %>%
  58. select(pais, ano_cat, n)
  59. write_delim(mun_by_year, "../app/data/radarchart/mun_by_year.csv", delim = ";")
  60. write_delim(micro_by_year, "../app/data/radarchart/micro_by_year.csv", delim = ";")
  61. write_delim(meso_by_year, "../app/data/radarchart/meso_by_year.csv", delim = ";")
  62. write_delim(uf_by_year, "../app/data/radarchart/uf_by_year.csv", delim = ";")
  63. write_delim(regiao_by_year, "../app/data/radarchart/regiao_by_year.csv", delim = ";")
  64. write_delim(pais_by_year, "../app/data/radarchart/pais_by_year.csv", delim = ";")