Skip to contents

Legend specification

Usage

tm_legend(
  title,
  show,
  orientation,
  design,
  reverse,
  na.show,
  position,
  width,
  height,
  stack,
  z,
  group.frame,
  resize_as_group,
  title.color,
  title.size,
  title.fontface,
  title.fontfamily,
  title.padding,
  title.align,
  text.color,
  text.size,
  text.fontface,
  text.fontfamily,
  format,
  frame,
  frame.lwd,
  frame.r,
  bg.color,
  bg.alpha,
  item.height,
  item.width,
  item.space,
  item.na.height,
  item.na.width,
  item.na.space,
  item.shape,
  ticks,
  ticks.disable.na,
  ticks.col,
  ticks.lwd,
  margins,
  margin.item.text,
  ...
)

tm_legend_hide()

tm_legend_combine(variable)

Arguments

title

Legend title

show

Show legend?

orientation

Orientation of the legend: "portrait" or "landscape"

design

Legend design "standard".

reverse

Should the legend be reversed?

na.show

Show NA values in legend?

position

Vector of two values, specifying the x and y coordinates. The first is either "left" or "right", the second either "top" or "bottom".

width

Width of the legend

height

Height of the legend

stack

stack

z

z

group.frame

group.frame

resize_as_group

resize_as_group

title.color

Color of the legend title

title.size

Size of the legend title

title.fontface

Font face of the legend title

title.fontfamily

Font family of the legend title

title.padding

Padding of the legend title

title.align

Title alignment

text.color

Color of the legend text

text.size

Size of the legend text

text.fontface

Font face of the legend text

text.fontfamily

Font family of the legend text

format

Use the format argument of the tm_scale_*() functions instead.

frame

frame

frame.lwd

frame line width

frame.r

Radius of the rounded frame corners. 0 means no rounding.

bg.color

Background color of the legend

bg.alpha

Background transparency of the legend

item.height

PARAM_DESCRIPTION

item.width

PARAM_DESCRIPTION

item.space

PARAM_DESCRIPTION

item.na.height

PARAM_DESCRIPTION

item.na.width

PARAM_DESCRIPTION

item.na.space

PARAM_DESCRIPTION

item.shape

PARAM_DESCRIPTION

ticks

List of vectors of size 2 that determines the horizontal tick mark lines (for portrait legends). The values are the y-values of begin and endpoint of each tick mark.

ticks.disable.na

Remove ticks for NA values

ticks.col

Legend ticks color

ticks.lwd

Legend ticks line widths

margins

PARAM_DESCRIPTION

margin.item.text

PARAM_DESCRIPTION

...

visual values, e.g. col, fill, lwd, can be specified. If so, they overrule the default visual values, which are determined by the drawn map objects (e.g. polygons)

variable

visual (or transformation) variable to combine the legend with: e.g. "fill" or "size"

Value

A tm_legend component

Examples

# Example using different settings from tm_legend()

tm_shape(World) +
  tm_polygons(
    fill = "HPI",
    fill.legend = tm_legend(
      title = "Home Price Index",
      design = "standard",
      title.color = "orange",
      bg.color = "purple",
      show = TRUE
  ),
    id = "name",
    # Format the labels using dollar sign
    fill.scale = tm_scale_intervals(
      label.format = function(x) format(x, big.mark = " ")),
)