Skip to contents

The viz_scalebar function adds a scalebar on the map.

Usage

viz_scalebar(
  map,
  id = NULL,
  pos = NULL,
  translate = "",
  units = "km",
  label = "",
  tickSize = 0.2,
  tickPadding = 5,
  distance = "",
  tickValues = "",
  labelAnchor = "start",
  ...
)

Arguments

map

A geovizr map object created using viz_create().

id

character. Optional. Unique layer id.

pos

numeric vector of length 2. Optional. Position [x, y] (default c(10, svg.height - 20)).

translate

numeric vector of length 2. Optional. Translation without changing size (default NA).

units

character. Optional. Units ("m","km","mi","ft") (default "km").

label

character. Optional. Label to display.

tickSize

numeric. Optional. Tick size (default 0.2).

tickPadding

numeric. Optional. Tick padding (default 5).

distance

numeric. Optional. Distance represented by the scalebar.

tickValues

numeric vector. Optional. Custom tick values.

labelAnchor

character. Optional. Label anchor ("start","middle","end") (default "start").

...

Additional SVG attributes applied to the scalebar.

Value

A modified `geoviz` map object with a new layer added. Rendering is performed using viz_render().

Examples

library(sf)
world <- st_read(
  system.file("gpkg/world.gpkg", package = "geovizr"),
  quiet = TRUE
)

viz_create(projection = "Mercator", background = "white") |>
  viz_path(datum = world[world$region == "Africa", ], fill = "#f1f3f5") |>
  viz_scalebar() |>
  viz_render()