Skip to contents

The viz_picto function creates a pictogram (symbol-based) map layer from a spatial data frame. It allows mapping qualitative variables to custom symbols and supports legend generation and ordering.

Usage

viz_picto(
  map,
  data = NULL,
  var,
  symbols = NULL,
  alphabetical = TRUE,
  legend = TRUE,
  leg_type = "vertical",
  leg_pos = c(10, 10),
  ...
)

Arguments

map

A geoviz map created with viz_create.

data

A spatial dataframe Use data to enable iteration over features.

var

character. Name of the categorical variable used for symbol assignment, or directly the name of a symbol.

symbols

character vector. Optional. Vector of available symbols. Symbols available: "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"

alphabetical

logical. Optional. Whether to sort legend items alphabetically (default TRUE).

legend

logical. Optional. Whether to display a legend (default TRUE).

leg_type

character. Optional. Legend orientation (default "vertical"). One of: "horizontal", "vertical".

leg_pos

numeric vector. Optional. Legend position (default c(10, 10)).

...

Additional parameters passed to rendering functions (e.g. strokeWidth). With the leg_ 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
)

viz_create(
  projection = "EqualEarth", zoomable = TRUE
) |>
viz_path(
  datum = world, fill = "#f1f3f5"
) |>
viz_picto(
  data = world, var = "region",
  symbols = c("human", "heart", "fist", "clover", "rocket", "plane"),
  leg_type = "horizontal",
  leg_pos = c(400, 350),
  leg_symbol_spacing = 40,
  fill = "#38896F"
) |>
viz_render()