Skip to contents

The viz_leg_symbol_vertical function adds a vertical legend for symbol layers. It displays categorized symbols arranged vertically with optional shapes and ordering. The function creates a legend layer in the SVG container and returns the layer identifier.

Usage

viz_leg_symbol_vertical(
  map,
  id = NULL,
  pos = c(0, 0),
  gap = 2,
  types = c("A", "B", "C", "D"),
  symbols = c("circle", "square", "triangle", "pentagon"),
  alphabetical = TRUE,
  symbol_size = 10,
  symbol_rotate = 0,
  symbol_spacing = 4,
  symbol_fill = "#2e2e2e",
  symbol_stroke = "#303030",
  symbol_strokeWidth = 0.5,
  symbol_background = FALSE,
  values_textAnchor = "middle",
  values_dx = 5,
  values_dy = 0,
  values_fill = "#363636",
  values_fontSize = 10,
  title = "Legend",
  title_fill = "#363636",
  title_fontSize = 16,
  subtitle = "",
  subtitle_fill = "#363636",
  subtitle_fontSize = 12,
  note = "",
  note_fill = "#363636",
  note_fontSize = 10,
  frame = FALSE,
  frame_margin = 15,
  frame_fill = "white",
  frame_stroke = "black",
  frame_fillOpacity = 0.5,
  ...
)

Arguments

map

A geoviz object created with viz_create.

id

character. Optional. Unique layer id.

pos

numeric vector of length 2. Optional. Legend position (default c(0, 0)).

gap

numeric. Optional. Gap between elements (default 2).

types

character vector. Optional. Category labels (default c("A","B","C","D")).

symbols

character vector. Optional. Symbol shapes (default c("circle","square","triangle","pentagon")).

alphabetical

logical. Optional. Sort types alphabetically (default TRUE).

symbol_size

numeric. Optional. Symbol size (default 10).

symbol_rotate

numeric. Optional. Rotation angle (default 0).

symbol_spacing

numeric. Optional. Spacing between symbols (default 4).

symbol_fill

character. Optional. Symbol fill color (default "#2e2e2e").

symbol_stroke

character. Optional. Symbol stroke color (default "#303030").

symbol_strokeWidth

numeric. Optional. Symbol stroke width (default 0.5).

symbol_background

logical. Optional. Add background circle (default FALSE).

values_textAnchor

character. Optional. Text anchor (default "middle").

values_dx

numeric. Optional. X shift (default 5).

values_dy

numeric. Optional. Y shift (default 0).

values_fill

character. Optional. Text color (default "#363636").

values_fontSize

numeric. Optional. Font size (default 10).

title

character. Optional. Legend title (default "Legend").

title_fill

character. Optional. Title color (default "#363636").

title_fontSize

numeric. Optional. Title size (default 16).

subtitle

character. Optional. Subtitle (default "").

subtitle_fill

character. Optional. Subtitle color (default "#363636").

subtitle_fontSize

numeric. Optional. Subtitle size (default 12).

note

character. Optional. Note (default "").

note_fill

character. Optional. Note color (default "#363636").

note_fontSize

numeric. Optional. Note size (default 10).

frame

logical. Optional. Draw frame (default FALSE).

frame_margin

numeric. Optional. Frame margin (default 15).

frame_fill

character. Optional. Frame fill (default "white").

frame_stroke

character. Optional. Frame stroke (default "black").

frame_fillOpacity

numeric. Optional. Frame opacity (default 0.5).

...

Additional SVG attributes.

Examples

library(sf)

world <- st_read(
  system.file("gpkg/world.gpkg", package = "geoviz"),
  quiet = TRUE
)

viz_create(projection = "EqualEarth", background = "white") |>
viz_path(datum = world, fill = "#f1f3f5") |>
viz_leg_symbol_vertical(pos = c(20, 20)) |>
viz_render()