The gridchoro function builds a choropleth map based on a
spatial grid aggregation. It first generates a grid from the input spatial data frame,
aggregates values within each cell, and maps them using a color classification.
Usage
viz_gridchoro(
map,
data = NULL,
var,
grid = "square",
step = 15,
level = 1,
ratio_factor = 1,
coords = "geo",
missing = "white",
fixmax = NULL,
legend = TRUE,
leg_type = "vertical",
leg_pos = c(10, 10),
...
)Arguments
- map
A
geovizmap created withviz_create.- data
A spatial dataframe Use
datato enable iteration over features.- var
character or character vector. Variable(s) used for aggregation. If two variables are provided, a ratio is computed.
- grid
character. Optional. Type of grid used for aggregation (default "square"). One of: "square", "dot", "diamond", "hexbin", "hex", "triangle", "arbitrary", "random", "h3", "h3geo", "hexgeo", "hexbingeo", "square_sph".
- step
numeric. Optional. Grid resolution (default 15).
- level
numeric. Optional. Subdivision level for hierarchical grids (default 1).
- ratio_factor
numeric. Optional. Multiplication factor applied to ratio values (default 1).
- coords
character. Optional. Coordinate system (default "geo"). One of: "geo", "svg".
- missing
character. Optional. Fill color for missing values (default "white").
- fixmax
numeric. Optional. Maximum value for color scaling. Useful for map comparability.
- legend
logical. Optional. Whether to display legend (default TRUE).
- leg_type
character. Optional. Legend type (default "vertical"). One of: "horizontal", "vertical".
- leg_pos
numeric vector. Optional. Legend position (default c(10, 10)).
- ...
Additional parameters passed to choropleth rendering (same as
viz_choro). With theleg_prefix, you can configure the legend. For example:leg_title,leg_subtitle,leg_note, etc.
Examples
library(sf)
world <- st_read(
system.file("gpkg/world.gpkg", package = "geoviz"),
quiet = TRUE
)
cities <- st_read(
system.file("gpkg/cities.gpkg", package = "geoviz"),
quiet = TRUE
)
viz_create(projection = "EqualEarth") |>
viz_path(datum = world, fill = "#f1f3f5") |>
viz_gridchoro(data = cities, var = "population") |>
viz_render()