The viz_symbol function draws SVG symbols on the map from a spatial
data frame. It allows the use of predefined symbols, scaling, rotation, and styling,
and can be used for categorical or proportional symbol maps.
Usage
viz_symbol(
map,
data = NULL,
id = NULL,
pos = c(0, 0),
fill = NULL,
stroke = "white",
strokeWidth = 0.2,
coords = "geo",
r = 12,
scale = NULL,
symbol = "star",
missing = "missing",
rotate = 0,
skewX = 0,
skewY = 0,
background = FALSE,
tip = FALSE,
k = 50,
fixmax = NULL,
dodge = FALSE,
iteration = 200,
sort = NULL,
descending = NULL,
...
)Arguments
- map
A
geovizmap created withviz_create.- data
object. Optional. A spatial data frame.
- id
character. Optional. Unique layer id.
- pos
numeric vector. Optional. Position of a single symbol (default c(0, 0)).
- fill
character or function. Optional. Fill color.
- stroke
character or function. Optional. Stroke color (default "white").
- strokeWidth
numeric or function. Optional. Stroke width (default 0.2).
- coords
character. Optional. Coordinate system (default "geo"). Use
"svg"if coordinates are already expressed in the SVG coordinate space.- r
numeric or character. Optional. Radius defining symbol size (default 12).
- scale
numeric. Optional. Global scale factor for symbols.
- symbol
character. Optional. Symbol name. "circle", "square", "triangle", "pentagon", "hexagon", "roundsquare", "pillow", "drop", "egg", "star12", "star8", "star", "diamond", "trapzium", "plus", "minus", "arrow", "stop", "vbar", "crescent", "donut", "heart", "clover", "fist", "check", "plane", "rocket", "boat", "pin", "hospital", "flower", "cloud", "human", "tent", "beer", "boom", "nuke", "target", "missing". (default "star"). different symbols are assigned per category.
- missing
character. Optional. Symbol used for missing values (default "missing"). Use
NULLto hide missing values.- rotate
numeric. Optional. Rotation angle (default 0).
- skewX
numeric. Optional. Horizontal skew (default 0).
- skewY
numeric. Optional. Vertical skew (default 0).
- background
logical. Optional. Add a background circle (default FALSE). You can confifure it with the prefix
background_(e.g.background_fill,background_stroke, etc.).- tip
logical or function. Optional. Tooltip definition (default FALSE). Use TRUE to display all fields.
- k
numeric. Optional. Maximum radius scaling value (default 50).
- fixmax
numeric. Optional. Value corresponding to the maximum radius
k.- dodge
logical. Optional. Avoid symbol overlap (default FALSE).
- iteration
numeric. Optional. Number of iterations for dodging (default 200).
- sort
character or function. Optional. Field name or function to sort symbols.
- descending
logical. Optional. Sorting order.
- ...
Additional SVG attributes (e.g.
strokeDasharray,opacity,strokeLinecap, etc.).
Examples
library(sf)
world <- st_read(
system.file("gpkg/world.gpkg", package = "geoviz"),
quiet = TRUE
)
viz_create(projection = "EqualEarth") |>
viz_path(datum = world, fill = "#f1f3f5") |>
viz_symbol(data = world, symbol = "star", fill = "#38896F") |>
viz_render()