map_comuni_choropleth.RdCreates a choropleth (colored) map by joining external data to municipality boundaries. Useful for visualizing statistics, census data, or any other municipality-level indicators.
map_comuni_choropleth(
comuni_sf,
data,
join_by = "PRO_COM",
value_col,
palette = "YlOrRd",
legend_title = value_col,
popup_fields = c("COMUNE", "DEN_REG")
)An sf object with municipality boundaries
A data.frame or data.table with values to visualize
Character string. Column name to join on (must exist in both comuni_sf and data). Default is "PRO_COM".
Character string. Column name in data containing values to visualize (e.g., population, income, etc.)
Character string. Color palette for choropleth. Options: "YlOrRd", "YlGnBu", "RdYlGn", "Spectral". Default is "YlOrRd".
Character string. Title for the legend.
Character vector. Additional fields to show in popup.
A leaflet map object
This function is now a wrapper around map_territorial_choropleth.
For more flexibility with different territorial units (provinces, regions, etc.),
consider using map_territorial_choropleth directly.
if (FALSE) { # \dontrun{
# Load municipality boundaries
files <- prepare_comuni_maps()
comuni <- readRDS(files$rds)
# Create sample data (e.g., population by municipality)
pop_data <- data.frame(
PRO_COM = sample(comuni$PRO_COM, 100),
population = runif(100, 1000, 100000)
)
# Create choropleth map
map_comuni_choropleth(
comuni,
data = pop_data,
value_col = "population",
legend_title = "Population"
)
} # }