Skip to contents

The viz_leg_box function creates a box legend. The function adds a legend layer to the map.

Usage

viz_leg_box(
  map,
  id = NULL,
  pos = c(0, 0),
  gap = 2,
  rect_width = 25,
  rect_height = 17,
  rect_fill = "#5d6266",
  rect_stroke = "#303030",
  rect_strokeWidth = 0.1,
  label = "",
  label_fill = "#363636",
  label_fontSize = 10,
  label_dx = 5,
  label_dominantBaseline = "central",
  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. ID of the layer.

pos

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

gap

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

rect_width

numeric. Optional. Width of the box (default 25).

rect_height

numeric. Optional. Height of the box (default 17).

rect_fill

character. Optional. Box fill color (default "#5d6266").

rect_stroke

character. Optional. Stroke color (default "#303030").

rect_strokeWidth

numeric. Optional. Stroke width (default 0.1).

label

character. Optional. Text displayed (default "").

label_fill

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

label_fontSize

numeric. Optional. Text size (default 10).

label_dx

numeric. Optional. Horizontal shift (default 5).

label_dominantBaseline

character. Optional. Dominant baseline (default "central").

title

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

title_fill

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

title_fontSize

numeric. Optional. Title font size (default 16).

subtitle

character. Optional. Subtitle of the legend (default "").

subtitle_fill

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

subtitle_fontSize

numeric. Optional. Subtitle font size (default 12).

note

character. Optional. Note displayed above the legend (default "").

note_fill

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

note_fontSize

numeric. Optional. Note font size (default 10).

frame

logical. Optional. Draw a frame around the legend (default FALSE).

frame_margin

numeric. Optional. Frame margin (default 15).

frame_fill

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

frame_stroke

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

frame_fillOpacity

numeric. Optional. Frame fill opacity (default 0.5).

...

Additional SVG attributes passed to elements (e.g. rect_*, label_*, title_*, subtitle_*, note_*, frame_*, text_*).

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_box(pos = c(20, 20), label = "Hello") |>
viz_render()