Skip to contents

The viz_leg_squares_nested function adds a legend for proportional nested squares. It displays squares scaled according to input values, optionally comparable via fixmax. The function adds a legend layer to the SVG container.

Usage

viz_leg_squares_nested(
  map,
  id = NULL,
  pos = c(0, 5),
  gap = 2,
  data = c(1, 1000),
  k = 50,
  fixmax = NULL,
  nb = 4,
  square_fill = "none",
  square_stroke = "#363636",
  square_spacing = 5,
  line_stroke = "#363636",
  line_strokeDasharray = "1",
  line_strokeWidth = 0.7,
  line_length = 10,
  values_textAnchor = "start",
  values_dx = 5,
  values_dy = 0,
  values_fill = "#363636",
  values_fontSize = 10,
  values_factor = 1,
  values_decimal = ".",
  values_thousands = " ",
  title = "",
  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, 5)).

gap

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

data

numeric vector. Required. Input values.

k

numeric. Optional. Side length of largest square (default 50).

fixmax

numeric. Optional. Value mapped to side k.

nb

numeric. Optional. Number of squares (default 4).

square_fill

character. Optional. Fill color (default "none").

square_stroke

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

square_spacing

numeric. Optional. Spacing between squares (default 5).

line_stroke

character. Optional. Line stroke color (default "#363636").

line_strokeDasharray

character. Optional. Dash pattern (default "1").

line_strokeWidth

numeric. Optional. Line width (default 0.7).

line_length

numeric. Optional. Line length (default 10).

values_textAnchor

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

values_dx

numeric. Optional. X shift (default 5).

values_dy

numeric. Optional. Y shift (default 0).

values_fill

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

values_fontSize

numeric. Optional. Font size (default 10).

values_factor

numeric. Optional. Scaling factor (default 1).

values_decimal

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

values_thousands

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

title

character. Optional. Title (default "").

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_squares_nested(pos = c(20, 20)) |>
viz_render()