The viz_pattern function creates a reusable SVG pattern
for thematic or cartographic styling. Patterns can be applied to any SVG shape
(e.g. paths, rectangles) and support multiple textures such as lines, crosses,
dots, waves, triangles, or zigzags. Patterns can also be clipped to a spatial
data frame geometry or to the Earth outline.
Usage
viz_pattern(
map,
id = NULL,
spacing = 6,
angle = 0,
fill = NULL,
stroke = "#786d6c",
strokeWidth = 2,
strokeOpacity = 0.1,
fillOpacity = 1,
strokeDasharray = NULL,
strokeLinecap = "butt",
strokeLinejoin = "miter",
strokeMiterlimit = 4,
opacity = 1,
visibility = "visible",
display = NULL,
pattern = "lines",
data = NULL,
clipOutline = FALSE,
...
)Arguments
- map
A
geovizmap created withviz_create.- id
character. Optional. Unique pattern id (auto-generated if not provided).
- spacing
numeric. Optional. Distance between pattern elements (default 6).
- angle
numeric. Optional. Pattern rotation in degrees (default 0).
- fill
character or NULL. Optional. Fill color of pattern elements.
- stroke
character. Optional. Stroke color (default "#786d6c").
- strokeWidth
numeric. Optional. Stroke width (default 2).
- strokeOpacity
numeric. Optional. Stroke opacity (default 0.1).
- fillOpacity
numeric. Optional. Fill opacity (default 1).
- strokeDasharray
character or NULL. Optional. Stroke dash pattern.
- strokeLinecap
character. Optional. Line cap style (default "butt").
- strokeLinejoin
character. Optional. Line join style (default "miter").
- strokeMiterlimit
numeric. Optional. Miter limit (default 4).
- opacity
numeric. Optional. Overall opacity (default 1).
- visibility
character. Optional. SVG visibility property (default "visible").
- display
character or NULL. Optional. SVG display property.
- pattern
character. Optional. Pattern type (default "lines"). One of: "lines", "cross", "dots", "waves", "triangles", "zigzag".
- data
object or NULL. Optional. Spatial data frame used to clip the pattern.
- clipOutline
logical. Optional. Clip pattern to Earth outline (default FALSE).
- ...
Additional SVG attributes (e.g.
strokeDasharray,opacity,strokeLinecap, etc.).
Examples
library(sf)
world <- st_read(
system.file("gpkg/world.gpkg", package = "geoviz"),
quiet = TRUE
)
africa <- world[world$region == "Africa", ]
viz_create(projection = "EqualEarth", background = "white") |>
viz_path(datum = world, fill = "#f1f3f5") |>
viz_pattern(
data = africa, stroke = "#38896F", pattern = "cross",
angle = 45, strokeWidth = 2, strokeOpacity = 0.6
) |>
viz_render()