Skip to contents

Adds a categorical or continuous legend. Legends can be conditionally displayed based on layer/view, and can be mounted via the panel by bind.

Usage

add_legend(
  map,
  title = NULL,
  type = c("categorical", "continuous"),
  position = c("bottomleft", "bottomright", "topleft", "topright"),
  values = NULL,
  colors = NULL,
  shapes = "square",
  sizes = NULL,
  range = NULL,
  labels = NULL,
  breaks = NULL,
  gradient = NULL,
  shape = "square",
  size = 12,
  layer = NULL,
  view = NULL,
  bind = NULL,
  id = NULL
)

Arguments

map

A maplamina widget created by maplamina().

title

Optional legend title.

type

Legend type: "categorical" or "continuous".

position

Legend position hint: "bottomleft", "bottomright", "topleft", "topright".

values, colors

Categorical legend labels and colors (same length).

shapes, sizes

Optional categorical shapes/sizes (length 1 or length(values)).

range, labels, breaks

Continuous legend range/labels/breaks.

gradient

Vector of 2+ colors for the continuous legend.

shape, size

Continuous legend swatch/shape and size.

layer, view

Optional conditional display rule.

bind

Bind group id for mounting in the panel (defaults to legend id).

id

Optional component id (otherwise generated).

Value

The modified map widget.

Examples

maplamina() |>
  add_legend(
    title = "Magnitude",
    type = "continuous",
    range = c(3, 7),
    gradient = c("lightyellow", "red")
  )