Creates 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")
)

Arguments

comuni_sf

An sf object with municipality boundaries

data

A data.frame or data.table with values to visualize

join_by

Character string. Column name to join on (must exist in both comuni_sf and data). Default is "PRO_COM".

value_col

Character string. Column name in data containing values to visualize (e.g., population, income, etc.)

palette

Character string. Color palette for choropleth. Options: "YlOrRd", "YlGnBu", "RdYlGn", "Spectral". Default is "YlOrRd".

legend_title

Character string. Title for the legend.

popup_fields

Character vector. Additional fields to show in popup.

Value

A leaflet map object

Note

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.

Examples

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"
)
} # }