1 Introducción Y fuente de datos

1.1 Qué es INDECOL y objetivo del informe

INDECOL (Indicadores Delictivos de Colombia) es un proyecto que analiza las cifras de criminalidad del país a partir de datos abiertos. Este informe documenta el proceso realizado en R: limpieza, análisis y hallazgos.

Objetivo: identificar qué delitos se presentan con mayor frecuencia en Colombia, dónde ocurren y cómo han cambiado en el tiempo, para ofrecer una visión clara de la criminalidad en el país.

1.2 Fuente de los datos

Los datos provienen del SIEDCO (Sistema de Información Estadístico, Delincuencial, Contravencional y Operativo) de la Policía Nacional de Colombia, consultado en su portal público. Se descargaron 34 bases de datos de delitos, que fueron limpiadas y unificadas en una sola base para este análisis.

# Importar la base de datos hechos
hechos <- read_parquet('hechos.parquet')
  • Fuente: Policía Nacional de Colombia, SIEDCO.

  • Portal de descarga: Portal público SIEDCO

  • Fecha de descarga: 3/11/2026.

  • Periodo cubierto: ENERO 2020 - OCTUBRE 2026.

# readxl para la lectura de archivos
library(readxl)

# dplyr para la manipulacion de datos.
library(dplyr)

# tidyr para la transformacion de datos.
library(tidyr)

# knitr para crear informe dinamicos y mejorar la presentacion.
library(knitr)

# ggplot para la creacion de graficos.
library(ggplot2)

# scale para controlar y personalizar la forma en que se muestran valores en gráficos.
library(scales)

library(sf)

library(geodata)

library(stringi)

1.3 Descripcion de la base de datos

la base de datos contiene 4.429.202 registros de delitos y 21 variables.


1.3.1 Nombre de las variables y su tipo de dato

campos <- data.frame(
  CAMPOS = names(hechos),
  TIPO_DATO = vapply(hechos, function(x) class(x)[1], character(1)))

kable(campos, col.names = c('VARIABLE','TIPO DE DATO'), row.names = F)
VARIABLE TIPO DE DATO
tematica character
delito character
año integer
mes character
departamento character
codigo_dane character
municipio character
edad character
genero character
zona character
dia character
descripcion_conducta character
cantidad numeric
region character
clase_sitio character
clase_bien character
unidad character
armas_medios character
tipo_bien character
vehiculo character
es_duplicado integer


1.3.2 Delitos y su cantidad de registros

delitos_row_can <- hechos %>%
  group_by(delito, unidad) %>%
  summarise(CANTIDAD_ROW = n(),
            CANTIDAD = sum(cantidad, na.rm = TRUE),
            .groups = "drop") %>%
  arrange(desc(CANTIDAD_ROW)) %>%
  mutate(
    CANTIDAD_ROW = format(CANTIDAD_ROW, big.mark = ".", decimal.mark = ","),
    CANTIDAD = ifelse(
      unidad == "GRAMOS",
      format(round(CANTIDAD, 2), big.mark = ".", decimal.mark = ",", nsmall = 2, trim = TRUE),
      format(round(CANTIDAD),    big.mark = ".", decimal.mark = ",", trim = TRUE))) %>%
  select(delito, CANTIDAD_ROW, CANTIDAD, unidad)

DT::datatable(
  delitos_row_can,
  colnames = c("DELITOS", "CANTIDAD DE REGISTROS", "CANTIDAD", "UNIDAD"),
  rownames = FALSE,
  options = list(
    pageLength = 10,
    lengthMenu = c(5, 10, 15, 20, 25, 30, 34),
    scrollX = TRUE,
    columnDefs = list(
      list(className = "dt-right", targets = c(1, 2)),
      list(className = "dt-center", targets = 3)),
    language = list(
      search = "Buscar:",
      lengthMenu = "Mostrar _MENU_ registros",
      info = "Mostrando _START_ a _END_ de _TOTAL_ delitos",
      paginate = list(
        previous = "Anterior",
        `next` = "Siguiente"),
      zeroRecords = "No se encontraron resultados")))


1.3.3 Cantidad de registros de cada categoria

categoria_row <- hechos %>%
  group_by(tematica) %>%
  summarise(CANTIDAD_ROW = n(), .groups = 'drop') %>%
  arrange(desc(CANTIDAD_ROW)) %>%
  mutate(CANTIDAD_ROW = format(CANTIDAD_ROW, big.mark = ".", decimal.mark = ','))
  
kable(categoria_row, col.names = c('CATEGORIA', 'CANTIDAD DE REGISTROS'), row.names = F)
CATEGORIA CANTIDAD DE REGISTROS
MODALIDADES DE HURTOS 1.465.650
DELITOS CONTRA LA VIDA E INTEGRIDAD 1.306.860
CONTROL DE ARMAS, SUSTANCIAS Y CAPTURAS 644.036
DELITOS CONTRA BIENES Y RECURSOS 332.367
VEHICULOS Y TRANSITO 280.756
DELITOS INFORMATICOS Y PROPIEDAD INTELECTUAL 268.183
GESTION Y FUNCION PUBLICA 102.656
PROTECCION AMBIENTAL Y ANIMAL 25.687
LIBERTAD, MOVILIDAD HUMANA Y SECUESTROS 3.007


2 Análisis Territorial

2.1 Distribución Por Departamento

library(dplyr)
library(sf)

# 1. Límites departamentales de Colombia (GADM)
colombia <- geodata::gadm(
  country = "COL",
  level = 1,
  path = tempdir()) %>%
  sf::st_as_sf() %>%
  mutate(
    DEP = stringi::stri_trans_general(NAME_1, "Latin-ASCII") %>%
      toupper() %>%
      trimws(),
    DEP = ifelse(grepl("BOGOT", DEP), "BOGOTA D.C.", DEP))

# 2. Total de delitos por departamento
delitos_departamento <- hechos %>%
  group_by(departamento) %>%
  summarise(TOTAL = n(), .groups = "drop") %>%
  mutate(
    DEP = stringi::stri_trans_general(departamento, "Latin-ASCII") %>%
      toupper() %>%
      trimws(),
    DEP = case_when(
      DEP == "GUAJIRA" ~ "LA GUAJIRA",
      grepl("BOGOT", DEP) ~ "BOGOTA D.C.",
      TRUE ~ DEP))

# 3. Unir mapa con datos
mapa_delitos <- colombia %>%
  left_join(delitos_departamento, by = "DEP")

# 4. Pasar a WGS84 y simplificar polígonos (evita el error de memoria de Pandoc)
# 4. Simplificar geometrías en coordenadas proyectadas
mapa_delitos <- mapa_delitos %>%
  sf::st_transform(9377) %>%
  sf::st_simplify(
    dTolerance = 200,
    preserveTopology = TRUE
  ) %>%
  sf::st_transform(4326)

gc()
##             used  (Mb) gc trigger   (Mb)  max used   (Mb)
## Ncells   2369162 126.6    4280528  228.7   4280528  228.7
## Vcells 122200347 932.4  227527572 1735.9 223439344 1704.8
library(leaflet)

# Paleta cálida que resalta sobre el satélite
pal <- colorBin(
  palette = c("#fff5d6", "#f2c46d", "#e08a3c", "#b8432f", "#6e1a1a"),
  domain = mapa_delitos$TOTAL,
  bins = 5,
  na.color = "transparent")

leaflet(mapa_delitos, height = 650, width = "100%") %>%
  addProviderTiles(providers$Esri.WorldImagery) %>%
  fitBounds(-79, -4.5, -66.8, 12.6) %>%
  addPolygons(
    fillColor = ~pal(TOTAL),
    fillOpacity = 0.55,
    color = "white",
    weight = 1.2,
    highlightOptions = highlightOptions(
      weight = 3, color = "yellow", fillOpacity = 0.75, bringToFront = TRUE),
    label = ~paste0(
      NAME_1, ": ",
      ifelse(is.na(TOTAL), "sin datos",
             format(TOTAL, big.mark = ".", decimal.mark = ",")))) %>%
  addLegend(
    pal = pal,
    values = ~TOTAL,
    title = "TOTAL DE REGISTROS",
    position = "bottomright",
    na.label = "Sin datos",
    labFormat = labelFormat(big.mark = ".", digits = 0))
departamentos_row <- hechos %>%
  group_by(departamento) %>%
  summarise(TOTAL = n(), .groups = "drop") %>%
  arrange(desc(TOTAL)) %>%
  mutate(
    PORCENTAJE = round(TOTAL / sum(TOTAL) * 100, 2),
    TOTAL = format(TOTAL, big.mark = ".", decimal.mark = ","),
    PORCENTAJE = paste0(
      format(PORCENTAJE, decimal.mark = ",", nsmall = 2),"%"))

DT::datatable(
  departamentos_row,
  colnames = c("DEPARTAMENTO", "TOTAL DE REGISTROS",'PORCENTAJE SOBRE TOTAL'),
  options = list(
    pageLength = 10,
    lengthMenu = c(5, 10, 15, 20, 25, 30, 34),
    scrollX = TRUE,
    language = list(
      search = "Buscar:",
      lengthMenu = "Mostrar _MENU_ registros",
      info = "Mostrando _START_ a _END_ de _TOTAL_ departamentos",
      paginate = list(
        previous = "Anterior",
        `next` = "Siguiente"),
      zeroRecords = "No se encontraron resultados")),
  rownames = FALSE)


2.2 Distribución Por Municipio

top10_municipios <- hechos %>%
  group_by(municipio) %>%
  summarise(TOTAL = n(), .groups = "drop") %>%
  arrange(desc(TOTAL)) %>%
  slice_head(n = 10) %>%
  mutate(
    PORCENTAJE = TOTAL / nrow(hechos) * 100,
    ETIQUETA = paste0(
      format(TOTAL, big.mark = ".", decimal.mark = ","),
      " (",
      round(PORCENTAJE, 2),
      "%)"))

ggplot(
  top10_municipios,
  aes(x = reorder(municipio, TOTAL), y = TOTAL)) +
  geom_col(fill = "#18363d", width = 0.7) +
  coord_flip() +
  geom_text(
    aes(label = ETIQUETA),
    hjust = -0.03,
    color = "#18363d",
    size = 3.5) +
  scale_y_continuous(
    labels = scales::label_comma(big.mark = ".", decimal.mark = ","),
    expand = expansion(mult = c(0, 0.25))) +
  labs(
    title = "TOP 10 MUNICIPIOS CON MÁS DELITOS",
    x = NULL,
    y = "TOTAL DE REGISTROS") +
  theme_minimal() +
  theme(
    plot.background = element_rect(fill = "white", color = NA),
    panel.background = element_rect(fill = "white", color = NA),
    plot.title = element_text(
      color = "#18363d",
      face = "bold",
      size = 14),
    axis.text = element_text(color = "#49666A"),
    axis.title = element_text(color = "#18363d", face = "bold"))

municipios <- hechos %>%
  group_by(municipio) %>%
  summarise(TOTAL = n(), .groups = "drop") %>%
  arrange(desc(TOTAL)) %>%
  mutate(
    PORCENTAJE = round(TOTAL / sum(TOTAL) * 100, 2),
    TOTAL = format(TOTAL, big.mark = ".", decimal.mark = ","),
    PORCENTAJE = paste0(format(PORCENTAJE, decimal.mark = ",", nsmall = 2),"%"))

DT::datatable(
  municipios,
  colnames = c("MUNICIPIOS", "TOTAL DE REGISTROS",'PORCENTAJE SOBRE TOTAL'),
  options = list(
    pageLength = 10,
    lengthMenu = c(seq(10, 1020, by = 10), 1022),
    scrollX = TRUE,
    language = list(
      search = "Buscar:",
      lengthMenu = "Mostrar _MENU_ registros",
      info = "Mostrando _START_ a _END_ de _TOTAL_ municipios",
      paginate = list(
        previous = "Anterior",
        `next` = "Siguiente"),
      zeroRecords = "No se encontraron resultados")),
  rownames = FALSE)