install.packages("readxl")
## Installing package into '/home/usuario/R/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
install.packages("leaflet")
## Installing package into '/home/usuario/R/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
## also installing the dependencies 'terra', 'raster'
## Warning in install.packages("leaflet"): installation of package 'terra' had
## non-zero exit status
## Warning in install.packages("leaflet"): installation of package 'raster' had
## non-zero exit status
install.packages("dplyr")
## Installing package into '/home/usuario/R/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
library(readxl)
library(dplyr)
##
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(leaflet)
archivo <- "~/Descargas/CAD - GUARDIA (respuestas) (1).xlsx"
datos <- read_excel(archivo, sheet = "Respuestas de formulario 1")
## New names:
## • `LOCALIDAD` -> `LOCALIDAD...14`
## • `LOCALIDAD` -> `LOCALIDAD...31`
# Corregir escala y filtrar valores válidos
datos <- datos %>%
mutate(
LAT = as.numeric(LAT) / 1e7,
LONG = as.numeric(LONG) / 1e7
) %>%
filter(!is.na(LAT), !is.na(LONG)) # eliminar coordenadas vacías
## Warning: There were 2 warnings in `mutate()`.
## The first warning was:
## ℹ In argument: `LAT = as.numeric(LAT)/1e+07`.
## Caused by warning:
## ! NAs introducidos por coerción
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
# Crear mapa centrado en Santa Fe, Argentina
leaflet(data = datos) %>%
addTiles() %>%
setView(lng = -60.7, lat = -31.6, zoom = 7) %>% # centrado en Santa Fe capital
addCircleMarkers(
~LONG, ~LAT,
radius = 5,
color = "blue",
stroke = FALSE,
fillOpacity = 0.8,
popup = ~`NOMBRE Y APELLIDO DEL ADOLESCENTE APREHENDIDO`,
label = ~`LOCALIDAD DE ACTUACIÓN`
)