Sinies_nacional<-read_excel("C:\\Users\\ADMIN.PC_ADMIN\\Downloads\\Copia de Siniestralidad_2018_2025p(1).xlsx")
Dep_colombia=st_read("C:\\Users\\ADMIN.PC_ADMIN\\Documents\\R_PROJECTS\\SHP\\MGN_ADM_DPTO_POLITICO.shp")
## Reading layer `MGN_ADM_DPTO_POLITICO' from data source
## `C:\Users\ADMIN.PC_ADMIN\Documents\R_PROJECTS\SHP\MGN_ADM_DPTO_POLITICO.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 33 features and 8 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -81.73562 ymin: -4.229406 xmax: -66.84722 ymax: 13.39473
## Geodetic CRS: MAGNA-SIRGAS
#---------------------
df_modificado=Sinies_nacional%>%
rename(dpto_ccdgo=CodigoDepartamentoHecho)
df_modificado=df_modificado %>%
group_by(dpto_ccdgo)%>%
summarise(total_fall=n(),.groups = "drop")
#---------------------
maps_co <- Dep_colombia %>%
left_join(df_modificado, by = "dpto_ccdgo")
#---------------------
paleta <- colorNumeric(
palette = "Reds",
domain = maps_co$total_fall, # Reemplaza 'Poblacion' con tu columna de valores
na.color = "transparent"
)
maps_co$etiquetas <- paste0(
"<b>Departamento: </b>", maps_co$dpto_cnmbr, # Columna con el nombre del departamento
"<br><b>Valor: </b>", format(maps_co$total_fall, big.mark = ",", scientific = FALSE)
)
leaflet(maps_co)%>%
addTiles()%>%
addPolygons(
fillColor = ~paleta(total_fall),
weight = 1.5,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.8,
highlightOptions = highlightOptions(
weight = 3,
color = "#666",
dashArray = "",
fillOpacity = 0.9,
bringToFront = TRUE),
label = ~lapply(etiquetas, HTML),
popup = ~lapply(etiquetas, HTML)
) %>%
addLegend(
pal = paleta,
values = ~total_fall,
opacity = 0.7,
title = "Cantidad total de siniestros con victimas fallecidas en Colombia (2018-2024)",
position = "bottomright"
)
## Warning: sf layer has inconsistent datum (+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs).
## Need '+proj=longlat +datum=WGS84'