The viz_smooth function creates smoothed density contours
(isobands) from a set of spatial points. It is a wrapper around contour-based
density estimation, with styling optimized for smooth thematic visualizations.
Usage
viz_smooth(
map,
data = NULL,
var = NULL,
id = NULL,
nb = 1e+05,
bandwidth = NULL,
fixbandwidth = FALSE,
thresholds = NULL,
cellSize = NULL,
stroke = "white",
strokeOpacity = 0.8,
strokeWidth = 0.3,
shadow = TRUE,
fill = NULL,
colors = "RdPu",
opacity = NULL,
fillOpacity = 0.6,
tip = NULL,
tipstyle = NULL,
coords = "geo",
legend = TRUE,
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 numeric. Optional. Variable used to weight points.
- id
character. Optional. Layer identifier.
- nb
numeric. Optional. Number of sampled points used for density estimation (default 100000).
- bandwidth
numeric. Optional. Bandwidth used for density computation.
- fixbandwidth
logical. Optional. Whether to scale bandwidth by zoom factor (default FALSE).
- thresholds
numeric. Optional. Number of contour levels.
- cellSize
numeric. Optional. Grid cell size for density computation.
- stroke
character. Optional. Stroke color (default "white").
- strokeOpacity
numeric. Optional. Stroke opacity (default 0.8).
- strokeWidth
numeric. Optional. Stroke width (default 0.3).
- shadow
logical. Optional. Whether to add a shadow filter (default TRUE).
- fill
character or function. Optional. Single fill color (used if
colorsis not defined).- colors
character. Optional. Name of a Dicopal sequential palette (default "RdPu"). See https://observablehq.com/@neocartocnrs/dicopal-library.
- opacity
numeric. Optional. Global opacity.
- fillOpacity
numeric. Optional. Fill opacity for polygons (default 0.6).
- tip
logical or function. Optional. Tooltip function; if TRUE displays all properties.
- tipstyle
list. Optional. Custom tooltip styling.
- coords
character. Optional. Coordinate system (default "geo"). One of: "geo", "svg".
- legend
logical. Optional. Whether to display legend (default TRUE).
- leg_pos
numeric vector. Optional. Legend position (default c(10, 10)).
- ...
Additional SVG attributes (e.g.
strokeDasharray,opacity,strokeLinecap, 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_smooth(data = cities, var = "population") |>
viz_render()