colonias_cdmx <- st_read("urbanismo_social_sintesis.shp")
## Reading layer `urbanismo_social_sintesis' from data source
## `C:\Users\manzo\OneDrive\Documentos\NLMR\urbanismo_social_sintesis.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 1815 features and 7 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 461655.7 ymin: 2106166 xmax: 506274.7 ymax: 2166535
## Projected CRS: WGS 84 / UTM zone 14N
st_geometry(colonias_cdmx)
## Geometry set for 1815 features
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 461655.7 ymin: 2106166 xmax: 506274.7 ymax: 2166535
## Projected CRS: WGS 84 / UTM zone 14N
## First 5 geometries:
ggplot(colonias_cdmx, aes(fill=C_US))+
geom_sf()+
scale_fill_viridis_c(option="F", direction = -1) +
labs(title = "Grado de marginación",
subtitle = "Por colonia en la Ciudad de México",
caption = "Elaborado con base a los datos abiertos del IECM (2022) y Índice de Desarrollo Social (IDS) 2020.",
fill="Grado de marginación")+
theme_minimal()+
theme(legend.position = "bottom",
text=element_text(size=10, family="Nutmeg-Light"),
plot.title = element_text(family="Nutmeg-Light"),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, family="Nutmeg-Light"))

data_map <- st_transform(colonias_cdmx, crs = '+proj=longlat +datum=WGS84')
palnumeric <- colorNumeric("inferno", domain = data_map$C_US, reverse = TRUE)
#paleta <- colorFactor("Set3", base$Año_inicio, reverse = T)
leaflet() %>% # Informacion geografica
addProviderTiles("CartoDB.Positron") %>%
#addPolygons(data = data_map, color = "blue", stroke = 1, opacity = 0.8)
addPolygons(data = data_map,
color = "#444444" ,
weight = .5, # Grosor de la linea de frontera
opacity = 1.0, # Opacidad del color de relleno
fillOpacity = 0.7, # Opacidad de la linea de frontera
fillColor = ~palnumeric(data_map$C_US), # Color de llenado
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE), #highlight cuando pasas el cursor
# label = ~leaf_merge$Feminicidios_total , # etiqueta cuando pasas el cursor
labelOptions = labelOptions(direction = "auto")) %>%
addLegend(position = "topleft", pal = palnumeric,
values = data_map$C_US,
title = "Grado de marginación")
base <- read.csv("da_victimas_completa_noviembre_2022.csv", encoding="UTF8") %>%
filter(Delito=="FEMINICIDIO") %>%
mutate(
label=paste(sep = "<br/>",
paste0("<B>Información</B> "),
paste0("Día de la semana: ", Año_inicio),
paste0("Categoría: ", Categoria),
paste0("Edad: ", Edad),
paste0("Colonia: ", colonia_datos),
paste0("Latitud: ", latitud),
paste0("Longitus: ", longitud))) %>%
group_by(longitud, latitud, label, Año_inicio, colonia_datos) %>%
summarise(Total=n())
## `summarise()` has grouped output by 'longitud', 'latitud', 'label',
## 'Año_inicio'. You can override using the `.groups` argument.
paleta <- colorFactor("Set1", base$Año_inicio, reverse = T)
leaflet() %>% addProviderTiles(providers$CartoDB.Positron) %>%
setView(lat=19.435827283154556, lng=-99.14107125397523, zoom=10) %>%
addCircleMarkers(lng = base$longitud, lat=base$latitud,
fillColor = paleta(base$Año_inicio),
fillOpacity =.50, color = paleta(base$Año_inicio),
opacity = .75, radius = base$Total*2,
popup = base$label) %>%
leaflet::addLegend(position = "topleft", pal = paleta,
values = base$Año_inicio,
title = "Año")
base %>%
leaflet() %>%
addTiles() %>%
setView(lat=19.435827283154556, lng=-99.14107125397523, zoom=11) %>%
addProviderTiles(providers$OpenStreetMap.DE) %>%
#setView(long_center,lat_center,6) %>%
addHeatmap(lng=~longitud,lat=~latitud,#intensity=~Trend,
max=1,radius=10#,blur=10
)
base %>%
leaflet() %>%
setView(lat=19.435827283154556, lng=-99.14107125397523, zoom=11) %>%
addTiles() %>%
addHeatmap(
lng = ~longitud, lat = ~latitud, intensity = ~Año_inicio,
blur = 20, # Difuminar. cantidad de desenfoque para aplicar
max = 0.05, # Intensidad máxima del punto
radius = 10)
paleta <- colorFactor("Dark2", base$Año_inicio, reverse = T)
leaflet() %>% addProviderTiles(providers$CartoDB.Positron) %>%
setView(lat=19.435827283154556, lng=-99.14107125397523, zoom=10) %>%
addPolygons(data = data_map,
color = "#444444" ,
weight = .5, # Grosor de la linea de frontera
opacity = 1.0, # Opacidad del color de relleno
fillOpacity = 0.25, # Opacidad de la linea de frontera
fillColor = ~palnumeric(data_map$C_US), # Color de llenado
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE), #highlight cuando pasas el cursor
# label = ~leaf_merge$Feminicidios_total , # etiqueta cuando pasas el cursor
labelOptions = labelOptions(direction = "auto")) %>%
addCircleMarkers(lng = base$longitud, lat=base$latitud,
fillColor = paleta(base$Año_inicio),
fillOpacity =0,
color = paleta(base$Año_inicio),
opacity = .75, radius = base$Total*4,
popup = base$label) %>%
addLegend(position = "topleft", pal = paleta,
values = base$Año_inicio,
title = "Año") %>%
addLegend(position = "topright", pal = paleta,
values = data_map$C_US,
title = "Grado de marginación")
## Warning in pal(v): Some values were outside the color scale and will be treated
## as NA