I use data from the National Statistical Directory of Economic Units (DENUE in spanish) of the National Institute of Statistics and Geography (INEGI in spanish).
This directory contains information on all the establishments in Mexico. For this assignment, I use the exact location provided by latitude and longitude. Specifically, I focus on veterinary services in the Mexico City.
Read the data from DENUE. This file contains all the stablishments in Mexico City.
denue_inegi <- read_csv("denue_inegi_09_.csv", show_col_types = F, locale = locale(encoding = "LATIN1"))
Filter by veterinary services. Based on the North American Industry Classification System, Mexico SCIAN 2023 used by INEGI.
This map shows the establishments
icon_gato <- makeIcon(
iconUrl = "pets.png",
iconWidth = 15,
iconHeight = 15)
leaflet(data = data_vet) %>%
addTiles() %>%
addMarkers(lng = ~longitud, lat = ~latitud, icon = icon_gato, label = ~nom_estab) %>%
addControl(html = "<h1 style='text-align: center; font-size: 16px; '> Veterinarian Services in Mexico City</h1>",
position = "topright" ) %>% setView(lng = -99.140487, lat = 19.430072, zoom = 13)
I present the total of veterinarian services by muinicipality. First, I aggregate the data by municipality.
data_vet$vet <- 1
data_vet_mun <- data_vet %>%
group_by(municipio) %>%
summarise(total_vet = sum(vet))
Read the shapefile with the municipality polygons.
Get the centroids, this step is just for the map.
mun_sf <- merge(shp_mun , data_vet_mun, by.x = "NOMGEO", by.y = "municipio", all.x = TRUE)
centroides <- st_centroid(mun_sf)
coords <- st_coordinates(centroides)
mun_sf$lon <- coords[,1]
mun_sf$lat <- coords[,2]
This map shows the total of veterianrian services by munipality in Mexico City.
leaflet(mun_sf) %>%
addTiles() %>%
# polígonos
addPolygons(
color = "darkblue",
weight = 2,
fillColor = "white",
fillOpacity = 0.5,
popup = ~paste0(NOMGEO, ": ", total_vet)
) %>%
addCircles(lng = ~lon, lat = ~lat,radius = ~total_vet*10,
color = "white",fillColor = "blue",fillOpacity = 0.7,popup = ~paste0(NOMGEO, ": ", total_vet) ) %>%
addControl(html = "<h1 style='text-align: center; font-size: 16px;'> Total of Veterinarian Services in Mexico City</h1>",
position = "topright" )