项目作者: robsalasco

项目描述 :
Chilean Municipalities Information System (SINIM) Wrapper 📈🏛🇨🇱
高级语言: R
项目地址: git://github.com/robsalasco/sinimr.git
创建时间: 2016-10-31T03:59:29Z
项目社区:https://github.com/robsalasco/sinimr

开源协议:MIT License

下载


saythanks
Donate
R-CMD-check
CoverageStatus

" class="reference-link">sinimR

Chilean Municipalities Information System Wrapper

What can I do with this?

This R package allows easy SINIM (http://sinim.gov.cl) data retrieval
what have advantages over the site:

  • When you work with multiple variables or years it will be very
    useful for rapid analyses.
  • Fast ploting directly from data source using the included
    geometries.
  • Data download with or without monetary correction using a switch.
  1. library(dplyr)
  2. library(sinimr)
  3. library(sf)
  4. library(tmap)
  5. varcode <- 882
  6. var <- get_sinim(varcode, 2018,
  7. region = 13,
  8. truevalue = T,
  9. geometry = T,
  10. auc = T,
  11. unit = "limites")
  12. gran_santiago_plot <- tm_shape(var) +
  13. tm_fill(col = "value",
  14. palette = "BuPu",
  15. border.col = "white",
  16. border.alpha = 0.5,
  17. lwd=1,
  18. style = "jenks",
  19. title = get_sinim_var_name(varcode))+
  20. tm_text("municipality", size = 0.4, style="jenks") +
  21. tm_legend(legend.position = c("left", "top"), legend.title.size = 1, legend.text.size = 0.6) +
  22. tm_compass(type = "8star", position = c(.85, .80)) +
  23. tm_scale_bar(breaks = c(0, 10), text.size = 0.75, position = c("right", "bottom")) +
  24. tm_credits("Fuente: Sistema Nacional de Información Municipal (SINIM), SUBDERE, Ministerio del Interior.", position=c("left", "bottom"), size=0.55)+
  25. tm_layout(legend.width=1,
  26. inner.margins = c(0.1, 0.1, 0.10, 0.1),
  27. legend.format = list(text.separator = "a",
  28. fun = mm)) +
  29. tm_borders(col = 'black')
  30. gran_santiago_plot

Support

FONDECYT Regular 2016 Nº 1161417, ¿Quién es responsable del desarrollo
local? Una geografía política del neoestructuralismo en “comunas de
exportación” (Comisión Nacional de Investigación Científica y
Tecnológica).

A note on usage

When querying the API, please be respectful of the resources required to
provide this data. Please retain the results for each request to avoid
repeated requests for duplicate information.

Installation

  1. install.packages("devtools")
  2. devtools::install_github("robsalasco/sinimr")

How do I use it?

sinimR comes with a small set of functions to deliver the content of
SINIM’s webpage. To get a first glance of the categories of information
what are available please use the get_sinim_cats() command.

  1. library(sinimr)
  2. get_sinim_cats()
  3. #> $`-`
  4. #> variable code
  5. #> 1 * SIM FIMU 539
  6. #>
  7. #> $`01. ADMINISTRACION Y FINANZAS MUNICIPALES`
  8. #> variable code
  9. #> 1 A.1. PRESUPUESTO INICIAL Y VIGENTE MUNICIPAL (M$) 517
  10. #> 2 A. INGRESOS MUNICIPALES (M$) 21
  11. #> 3 B. INGRESOS MUNICIPALES (%) 191
  12. #> 4 C. GASTOS MUNICIPALES (M$) 22
  13. #> 5 D. GASTOS MUNICIPALES (%) 172
  14. #> 6 E. GASTOS EN PERSONAL 169
  15. #> 7 F. TRANSFERENCIAS E INVERSION 170
  16. #> 8 G. SERVICIOS BASICOS Y GENERALES 370
  17. #> 9 I. TRANSFERENCIAS Y COMPENSACIONES SUBDERE 485
  18. #> 10 J. FONDO COMÚN MUNICIPAL (FCM) 508
  19. #> 11 K. GESTION MUNICIPAL 486
  20. #> 12 L. 24
  21. #> 13 M. 506
  22. #>
  23. #> $`02. RECURSOS HUMANOS MUNICIPAL`
  24. #> variable code
  25. #> 1 A. PERSONAL DE PLANTA 381
  26. #> 2 B. PERSONAL A CONTRATA 382
  27. #> 3 C. HONORARIOS 383
  28. #> 4 D. OTROS INDICADORES 384
  29. #>
  30. #> $`03. EDUCACION MUNICIPAL`
  31. #> variable code
  32. #> 1 A. ANTECEDENTES GENERALES DE EDUCACION 38
  33. #> 2 B. ASISTENCIA Y MATRÍCULAS EN EDUCACION 32
  34. #> 3 C. RESULTADOS PSU 33
  35. #> 4 D. INGRESOS EN EDUCACION MUNICIPAL 35
  36. #> 5 E. GASTOS EN EDUCACION MUNICIPAL 36
  37. #> 6 F. RECURSOS HUMANOS EN SECTOR EDUCACION 34
  38. #> 7 G. ESTABLECIMIENTOS DE EDUCACION MUNICIPAL 379
  39. #>
  40. #> $`04. SALUD MUNICIPAL`
  41. #> variable code
  42. #> 1 A. ANTECEDENTES GENERALES DE SALUD 30
  43. #> 2 B. COBERTURA EN SALUD MUNICIPAL 25
  44. #> 3 C. INGRESOS EN SALUD MUNICIPAL 26
  45. #> 4 D. GASTOS EN SALUD MUNICIPAL 28
  46. #> 5 E. RED ASISTENCIAL SALUD 31
  47. #> 6 F. RECURSOS HUMANOS EN SALUD 362
  48. #>
  49. #> $`05. SOCIAL Y COMUNITARIA`
  50. #> variable code
  51. #> 1 A. INFORMACION ENCUESTA CASEN 47
  52. #> 2 B. RED SOCIAL (SUBSIDIOS Y PENSIONES) 44
  53. #> 3 C. INTERMEDIACION LABORAL 43
  54. #> 4 D. ORGANIZACIONES COMUNITARIAS 46
  55. #> 5 E. BECAS 377
  56. #> 6 F. PARTICIPACIÓN CIUDADANA 510
  57. #> 7 G. DISCAPACIDAD 512
  58. #> 8 H. PREVENCIÓN DEL DELITO 511
  59. #>
  60. #> $`06. DESARROLLO Y GESTION TERRITORIAL`
  61. #> variable code
  62. #> 1 A. CARACTERISTICAS TERRITORIALES 39
  63. #> 2 B. SERVICIOS BASICOS A LA COMUNIDAD 41
  64. #> 3 C. INFRAESTRUCTURA 40
  65. #> 4 D. CATASTRO PREDIOS Y VALORACION CATASTRAL 300
  66. #> 5 E. AREAS VERDES 376
  67. #> 6 F. PLAN DE DESARROLLO COMUNAL (PLADECO) 304
  68. #> 7 G. PLAN REGULADOR COMUNAL 42
  69. #>
  70. #> $`07. CARACTERIZACION COMUNAL`
  71. #> variable code
  72. #> 1 A. GEOGRAFICO ADMINISTRATIVA 49
  73. #> 2 B. POBLACION 50
  74. #>
  75. #> $`08. GENERO`
  76. #> variable code
  77. #> 1 A. DOTACION FUNCIONARIA Y PROFESIONAL DE MUJERES 262
  78. #>
  79. #> $`09. CEMENTERIO`
  80. #> variable code
  81. #> 1 1. INFORMACION GENERAL 516
  82. #> 2 A. INGRESOS CEMENTERIO (M$) 456
  83. #> 3 B. GASTOS CEMENTERIO (M$) 457

Every category have a bunch of variables associated. Use the CODE number
and the get_sinim_vars() function to get them.

  1. get_sinim_vars(517)
  2. #> variable unit code
  3. #> 108 Presupuesto Inicial Sector Municipal M$ 4210
  4. #> 109 Presupuesto Inicial Gastos Municipales M$ 4211
  5. #> 110 Presupuesto Vigente Sector Municipal M$ 4212
  6. #> 111 Presupuesto Vigente Gastos Municpiales M$ 4213
  7. #> 112 Presupuesto Vigente Saldo Inicial de Caja Sector Municipal M$ 4226
  8. #> 113 Presupuesto Inicial Saldo Inicial de Caja sector Municipal M$ 4441

Finally, to obtain the data across municipalities use the code column
and specify a year.

  1. head(get_sinim(c(4210, 4211), 2015))
  2. #> code municipality year variable value
  3. #> 1 1101 IQUIQUE 2015 PRESUPUESTO INICIAL GASTOS MUNICIPALES 35295076
  4. #> 2 1107 ALTO HOSPICIO 2015 PRESUPUESTO INICIAL GASTOS MUNICIPALES 10263084
  5. #> 3 1401 POZO ALMONTE 2015 PRESUPUESTO INICIAL GASTOS MUNICIPALES 7685704
  6. #> 4 1402 CAMIÑA 2015 PRESUPUESTO INICIAL GASTOS MUNICIPALES 1319970
  7. #> 5 1403 COLCHANE 2015 PRESUPUESTO INICIAL GASTOS MUNICIPALES 2130495
  8. #> 6 1404 HUARA 2015 PRESUPUESTO INICIAL GASTOS MUNICIPALES 3267375

By default the values are in miles de millones but it can be
disabled using the truevalue = T switch.

  1. head(get_sinim(c(4210, 4211), 2015, truevalue = T))
  2. #> code municipality year variable value
  3. #> 1 1101 IQUIQUE 2015 PRESUPUESTO INICIAL GASTOS MUNICIPALES 35295076000
  4. #> 2 1107 ALTO HOSPICIO 2015 PRESUPUESTO INICIAL GASTOS MUNICIPALES 10263084000
  5. #> 3 1401 POZO ALMONTE 2015 PRESUPUESTO INICIAL GASTOS MUNICIPALES 7685704000
  6. #> 4 1402 CAMIÑA 2015 PRESUPUESTO INICIAL GASTOS MUNICIPALES 1319970000
  7. #> 5 1403 COLCHANE 2015 PRESUPUESTO INICIAL GASTOS MUNICIPALES 2130495000
  8. #> 6 1404 HUARA 2015 PRESUPUESTO INICIAL GASTOS MUNICIPALES 3267375000

You can get multiple years too! use the command get_sinim() and add
more years as in the example.

  1. head(get_sinim(880, 2015:2017))
  2. #> code municipality year variable value
  3. #> 1 1101 IQUIQUE 2017 INGRESOS POR FONDO COMÚN MUNICIPAL 3439830
  4. #> 2 1107 ALTO HOSPICIO 2017 INGRESOS POR FONDO COMÚN MUNICIPAL 7258188
  5. #> 3 1401 POZO ALMONTE 2017 INGRESOS POR FONDO COMÚN MUNICIPAL 1888333
  6. #> 4 1402 CAMIÑA 2017 INGRESOS POR FONDO COMÚN MUNICIPAL 1626482
  7. #> 5 1403 COLCHANE 2017 INGRESOS POR FONDO COMÚN MUNICIPAL 1156020
  8. #> 6 1404 HUARA 2017 INGRESOS POR FONDO COMÚN MUNICIPAL 1406921

The geometries are available in long format using the geometry=T
argument. By default it uses the comunal geographies but the
limite urbano censal is also available. The switches are
unit="comunas" and unit="limites". Note: Using limites not all
features are available because some comunas are not related to urban
zones. As shown in the example below you can obtain multiple years and
variables in long format.

  1. head(get_sinim(882, 2015:2017, geometry=T))
  2. #> Simple feature collection with 6 features and 5 fields
  3. #> geometry type: MULTIPOLYGON
  4. #> dimension: XY
  5. #> bbox: xmin: -70.20924 ymin: -21.43871 xmax: -69.81985 ymax: -20.04854
  6. #> geographic CRS: WGS 84
  7. #> code municipality year variable value
  8. #> 1 1101 IQUIQUE 2016 INGRESOS PROPIOS (IPP Y FCM) 36638105
  9. #> 2 1101 IQUIQUE 2015 INGRESOS PROPIOS (IPP Y FCM) 35186041
  10. #> 3 1101 IQUIQUE 2017 INGRESOS PROPIOS (IPP Y FCM) 37924449
  11. #> 4 1107 ALTO HOSPICIO 2017 INGRESOS PROPIOS (IPP Y FCM) 11377923
  12. #> 5 1107 ALTO HOSPICIO 2016 INGRESOS PROPIOS (IPP Y FCM) 10913779
  13. #> 6 1107 ALTO HOSPICIO 2015 INGRESOS PROPIOS (IPP Y FCM) 10705074
  14. #> geometry
  15. #> 1 MULTIPOLYGON (((-70.09894 -...
  16. #> 2 MULTIPOLYGON (((-70.09894 -...
  17. #> 3 MULTIPOLYGON (((-70.09894 -...
  18. #> 4 MULTIPOLYGON (((-70.1095 -2...
  19. #> 5 MULTIPOLYGON (((-70.1095 -2...
  20. #> 6 MULTIPOLYGON (((-70.1095 -2...

Another interesting feature is the possibility to subset by different
contexts. e.g if you want the comunas of Antofagasta region this command
is available. The command works with or without the presence of the
geometry switch and other switches are avaiblable too region,
provincia and comuna all working with codes.

  1. head(get_sinim(882, 2015:2017, geometry=T, region=2))
  2. #> Simple feature collection with 6 features and 5 fields
  3. #> geometry type: MULTIPOLYGON
  4. #> dimension: XY
  5. #> bbox: xmin: -70.62886 ymin: -25.40293 xmax: -68.0676 ymax: -22.4254
  6. #> geographic CRS: WGS 84
  7. #> code municipality year variable value
  8. #> 1 2101 ANTOFAGASTA 2015 INGRESOS PROPIOS (IPP Y FCM) 50480057
  9. #> 2 2101 ANTOFAGASTA 2017 INGRESOS PROPIOS (IPP Y FCM) 53481425
  10. #> 3 2101 ANTOFAGASTA 2016 INGRESOS PROPIOS (IPP Y FCM) 53775528
  11. #> 4 2102 MEJILLONES 2016 INGRESOS PROPIOS (IPP Y FCM) 7031571
  12. #> 5 2102 MEJILLONES 2015 INGRESOS PROPIOS (IPP Y FCM) 6400071
  13. #> 6 2102 MEJILLONES 2017 INGRESOS PROPIOS (IPP Y FCM) NA
  14. #> geometry
  15. #> 1 MULTIPOLYGON (((-70.60654 -...
  16. #> 2 MULTIPOLYGON (((-70.60654 -...
  17. #> 3 MULTIPOLYGON (((-70.60654 -...
  18. #> 4 MULTIPOLYGON (((-69.97002 -...
  19. #> 5 MULTIPOLYGON (((-69.97002 -...
  20. #> 6 MULTIPOLYGON (((-69.97002 -...

You can get a subset too

  1. head(get_sinim(882, 2015:2017, geometry=T, region=c(2,3)))
  2. #> Simple feature collection with 6 features and 5 fields
  3. #> geometry type: MULTIPOLYGON
  4. #> dimension: XY
  5. #> bbox: xmin: -70.62886 ymin: -25.40293 xmax: -68.0676 ymax: -22.4254
  6. #> geographic CRS: WGS 84
  7. #> code municipality year variable value
  8. #> 1 2101 ANTOFAGASTA 2016 INGRESOS PROPIOS (IPP Y FCM) 53775528
  9. #> 2 2101 ANTOFAGASTA 2015 INGRESOS PROPIOS (IPP Y FCM) 50480057
  10. #> 3 2101 ANTOFAGASTA 2017 INGRESOS PROPIOS (IPP Y FCM) 53481425
  11. #> 4 2102 MEJILLONES 2016 INGRESOS PROPIOS (IPP Y FCM) 7031571
  12. #> 5 2102 MEJILLONES 2015 INGRESOS PROPIOS (IPP Y FCM) 6400071
  13. #> 6 2102 MEJILLONES 2017 INGRESOS PROPIOS (IPP Y FCM) NA
  14. #> geometry
  15. #> 1 MULTIPOLYGON (((-70.60654 -...
  16. #> 2 MULTIPOLYGON (((-70.60654 -...
  17. #> 3 MULTIPOLYGON (((-70.60654 -...
  18. #> 4 MULTIPOLYGON (((-69.97002 -...
  19. #> 5 MULTIPOLYGON (((-69.97002 -...
  20. #> 6 MULTIPOLYGON (((-69.97002 -...

But where obtain the codes? a database is provided and you can filter it
using the standard R functions.

  1. head(id_geo_census)
  2. #> code municipality code.reg nom.reg code.prov nom.prov auc
  3. #> 1 1101 IQUIQUE 1 TARAPACA 11 IQUIQUE 1
  4. #> 2 1107 ALTO HOSPICIO 1 TARAPACA 11 IQUIQUE 1
  5. #> 3 1401 POZO ALMONTE 1 TARAPACA 14 TAMARUGAL 0
  6. #> 4 1402 CAMIÑA 1 TARAPACA 14 TAMARUGAL 0
  7. #> 5 1403 COLCHANE 1 TARAPACA 14 TAMARUGAL 0
  8. #> 6 1404 HUARA 1 TARAPACA 14 TAMARUGAL 0

Related to variables if you don’t know what are you looking for use
search_sinim_vars()to get search results based on variable
descriptions, names and groups.

  1. search_sinim_vars("cementerio")
  2. #> code
  3. #> 361 4140
  4. #> 362 4141
  5. #> 363 4406
  6. #> 364 4407
  7. #> variable
  8. #> 361 Ingresos Cementerio (Ingreso Total Percibido)
  9. #> 362 Gastos Cementerio (Gasto Total Devengado)
  10. #> 363 ¿La Municipalidad o Corporación administra Cementerio?
  11. #> 364 Si la Municipalidad o Corporación administra Cementerio, indique si tiene presupuesto propio. SI = presupuesto propio o independiente.
  12. #> description
  13. #> 361 Ingreso total percibido del sector Cementerio (clasificador presupuestario)
  14. #> 362 Gastos total devengado sector Cementerio (clasificador presupuestario).
  15. #> 363 Indica si la Municipalidad o Corporación administra o no Cementerio Municipal, ya sea con presupuesto propio o asociado a otro sector de la municipalidad o corporación.
  16. #> 364 Indica si administra un presupuesto independiente o anexo a otro sector de la municipalidad, como Salud, Municipalidad, etc.
  17. #> area subarea unit
  18. #> 361 09. CEMENTERIO A. INGRESOS CEMENTERIO (M$) M$
  19. #> 362 09. CEMENTERIO B. GASTOS CEMENTERIO (M$) M$
  20. #> 363 09. CEMENTERIO 1. INFORMACION GENERAL S-N
  21. #> 364 09. CEMENTERIO 1. INFORMACION GENERAL S-N

Advanced usage

SINIM (Sistema Nacional de Información Municipal) by default applies a
monetary correction to show current values of variables. The original
values provided by municipalities are available using the moncorr = F
switch. And if you want geographical identifiers like region or
provincia you can apply them using idgeo = T switch.

Other example plots

Multiple variable faceted plot

  1. library(tmap)
  2. library(dplyr)
  3. library(stringr)
  4. library(sinimr)
  5. library(sf)
  6. data_sinim <- get_sinim(var = c(3954,4174,880,1226,4251,4173),
  7. year = 2018,
  8. region = 13,
  9. geometry = T,
  10. truevalue = T,
  11. auc = T,
  12. unit = "limites")
  13. gran_santiago_plot <- tm_shape(data_sinim) +
  14. tm_fill(col = "value",
  15. palette = "BuPu",
  16. border.col = "white",
  17. border.alpha = 0.5,
  18. lwd=1,
  19. style = "jenks",
  20. title = "variable")+
  21. tm_text("municipality", size = 0.4) +
  22. tm_style("white", frame = T, legend.title.size = 1, legend.width=1) +
  23. tm_layout(inner.margins = c(0.01, 0.1, 0.1, 0.01),
  24. outer.margins = c(0.01, 0.01, 0.01, 0.01),
  25. design.mode=F,
  26. legend.format = list(text.separator = "a",
  27. fun = mm))+
  28. tm_borders(col = 'black') +
  29. tm_facets(by="variable", ncol = 2)
  30. gran_santiago_plot

A variable in multiple years using facets

  1. library(dplyr)
  2. library(sinimr)
  3. library(sf)
  4. library(tmap)
  5. var <- get_sinim(c(880, 882, 1226),
  6. 2016:2018,
  7. region = 13,
  8. truevalue = T,
  9. geometry = T,
  10. auc = T,
  11. unit = "limites")
  12. gran_santiago_plot <- tm_shape(var) +
  13. tm_fill("value",
  14. palette="BuPu",
  15. border.col = "white",
  16. style = "jenks",
  17. border.alpha = 0.5,
  18. lwd=1) +
  19. tm_text("municipality", size = 0.4) +
  20. tm_legend(legend.position = c("left", "top")) +
  21. tm_layout(legend.width=0.09,
  22. inner.margins = c(0.01, 0.1, 0.1, 0.01),
  23. outer.margins = c(0.01, 0.01, 0.01, 0.01),
  24. legend.format = list(text.separator = "a",
  25. fun = mm)) +
  26. tm_facets(by=c("year","variable"),) +
  27. tm_borders(col = 'black')
  28. gran_santiago_plot

Multiple variables and years using geofacet

  1. library(sf)
  2. library(dplyr)
  3. library(geofacet)
  4. library(sinimr)
  5. library(ggplot2)
  6. library(zoo)
  7. library(scales)
  8. library(ggpubr)
  9. data <- get_sinim(882, 2002:2018,
  10. region = 13,
  11. moncorr = F,
  12. truevalue = T,
  13. auc = T)
  14. data$year <- as.numeric(as.character(data$year))
  15. data$year <- as.Date(as.yearmon(data$year, "1-%y"))
  16. reg13 <- geogrid::read_polygons("https://raw.githubusercontent.com/robsalasco/precenso_2016_geojson_chile/master/Extras/GRAN_SANTIAGO.geojson")
  17. #> Warning: 'geogrid::read_polygons' is deprecated.
  18. #> Use 'sf::st_read' instead.
  19. #> See help("Deprecated")
  20. #> Reading layer `R13' from data source `https://raw.githubusercontent.com/robsalasco/precenso_2016_geojson_chile/master/Extras/GRAN_SANTIAGO.geojson' using driver `GeoJSON'
  21. #> Simple feature collection with 37 features and 8 fields
  22. #> geometry type: POLYGON
  23. #> dimension: XY
  24. #> bbox: xmin: -70.84306 ymin: -33.65716 xmax: -70.43015 ymax: -33.31069
  25. #> geographic CRS: WGS 84
  26. grd <- grid_auto(reg13, seed = 1, names = "NOM_COMUNA", codes = "COMUNA")
  27. #grid_preview(grd, label = "name_NOM_COMUNA")
  28. #grid_design(grd, label = "name_NOM_COMUNA")
  29. ggplot(data, aes(year, value, group=1)) +
  30. geom_line(color = "steelblue") +
  31. facet_geo(~ municipality, grid = grd, scales = "free_y")+
  32. scale_x_date() +
  33. scale_y_continuous(labels = dollar_format(suffix = "", prefix = "$", big.mark = ".", decimal.mark=","))+
  34. theme_bw()

Citation

  1. citation("sinimr")
  2. #>
  3. #> To cite package 'sinimr' in publications use:
  4. #>
  5. #> Roberto Salas (2019). sinimr: Chilean Municipalities Information
  6. #> System Wrapper. R package version 0.3.0.
  7. #> https://github.com/robsalasco/sinimr
  8. #>
  9. #> A BibTeX entry for LaTeX users is
  10. #>
  11. #> @Manual{,
  12. #> title = {sinimr: Chilean Municipalities Information System Wrapper},
  13. #> author = {Roberto Salas},
  14. #> year = {2019},
  15. #> note = {R package version 0.3.0},
  16. #> url = {https://github.com/robsalasco/sinimr},
  17. #> }

References

  • Sistema Nacional de Información Municipal (SINIM), SUBDERE,
    Ministerio del Interior.