Skip to contents

Set the legend title, placement, columns, explanatory note and area display aliases.

Usage

set_legend(x, title = "Reading this view",
           position = c("below", "above", "sidebar"),
           columns = NULL, visible = TRUE, show_counts = TRUE,
           note = NULL, labels = NULL, missing_label = "Unavailable or unmatched")

Arguments

x

An atlas object.

title

Plain-text legend title.

position

Legend location: below, above, or sidebar.

columns

NULL for responsive legend columns, or an integer from 1 to 4. Narrow screens and sidebar legends collapse to one column. Figure exports use the specified number, or three by default.

visible

Show legend keys and explanation in the viewer and image exports.

show_counts

Include current-period counts in categorical legend labels.

note

Optional legend explanation. NULL retains the generated explanation; an empty string suppresses it. Captions, source attribution and notices remain.

labels

NULL or a named list keyed by original area variable column, with one display label per interval or category. Missing labels are configured separately.

missing_label

Legend wording for unavailable or unmatched areas.

Details

Legend labels affect display only; original values and category names remain in CSV and JSON. Numeric label vectors follow interval order; category labels follow declared category order. Their lengths and variable names are checked at export, so presentation may be configured before adding data. For network legends, relationship names come from the supplied layer column. Custom legend text and fonts are preserved in SVG and PNG. Placement affects the HTML layout; exported legend keys follow the map and optional history chart. Configuration functions replace their own options using the supplied arguments and defaults. These settings contain plain text and enumerated choices, not arbitrary CSS, HTML, or JavaScript. All configuration is embedded in the standalone export.

Hiding a legend retains source attribution and export captions. A custom note replaces the automatic explanation, so keep any information needed to interpret symbols. The static area adapter honors these options where applicable.

Value

An offline_atlas object, suitable for piping into another configuration function or export_html.

See also

add_areas, set_controls, set_style, as_ggplot.

For the tutorial, see the offlineatlas package overview.

Examples

m <- atlas("Custom legend") |>
  set_legend(title = "How to read this map", position = "below",
             columns = 2, missing_label = "No observation")