Skip to contents

The viz_leg_choro_vertical function creates a vertical legend for choropleth layers. The function adds a legend layer to the map.

Usage

viz_leg_choro_vertical(
  map,
  id = NULL,
  pos = c(0, 0),
  gap = 2,
  breaks = c(1, 2, 3, 4, 5),
  colors = c("#fee5d9", "#fcae91", "#fb6a4a", "#cb181d"),
  rect_width = 25,
  rect_height = 17,
  rect_spacing = 0,
  rect_fill = "#5d6266",
  rect_stroke = "#303030",
  rect_strokeWidth = 0.1,
  values_textAnchor = "start",
  values_dx = 5,
  values_dy = 0,
  values_fill = "#363636",
  values_fontSize = 10,
  values_factor = 1,
  values_decimal = ".",
  values_thousands = " ",
  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).

breaks

numeric vector. Optional. Break values (default c(1, 2, 3, 4, 5)).

colors

character vector. Optional. Colors (default c("#fee5d9", "#fcae91", "#fb6a4a", "#cb181d")).

rect_width

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

rect_height

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

rect_spacing

numeric. Optional. Spacing between boxes (default 0).

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).

values_textAnchor

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

values_dx

numeric. Optional. Horizontal shift (default 5).

values_dy

numeric. Optional. Vertical shift (default 0).

values_fill

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

values_fontSize

numeric. Optional. Font size (default 10).

values_factor

numeric. Optional. Multiplication factor for displayed values (default 1).

values_decimal

character. Optional. Decimal separator (default ".").

values_thousands

character. Optional. Thousands separator (default " ").

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_*, values_*, 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_choro_vertical(pos = c(20, 20)) |>
viz_render()