Skip to contents

The viz_create function initializes a geoviz map by creating an SVG container and defining its main configuration (projection, domain, size, margins, and layout). It is the first step in any map construction workflow.

Usage

viz_create(
  id = "map",
  width = NULL,
  resize = TRUE,
  domain = NULL,
  responsive = TRUE,
  projection = NULL,
  background = NULL,
  fontFamily = NULL,
  margin = c(0, 0, 0, 0),
  zoomable = NULL,
  control = TRUE,
  warning = TRUE
)

Arguments

id

character. Optional. ID of the SVG container (default "map").

width

numeric. Optional. It allows you to manually set the width of the map. (default size of the device). Note that if responsive = TRUE, the SVG always has the size defined by the width in map coordinates, which does not correspond to the actual displayed size of the map. Similarly, if resize = TRUE, the size of the map is updated every time the window is resized.

resize

logical. If TRUE, the widget automatically redraw when the container size changes. Everything is recalculated every time the window is resized (default FALSE)

domain

spatial dataframe. Optional. Geographic domain to display.

responsive

logical. Optional. Whether the SVG map resizes with the container Nothing is recalculated. It’s just the image that is enlarged or reduced. (default TRUE).

projection

character. Optional. D3 Map projection (e.g. "mercator", "equalearth", "Polar", "Spilhaus",...).

background

character. Optional. Background color.

fontFamily

character. Optional. Font family applied to the entire map.

margin

numeric or vector. Optional. Map margins (default 0). Can be a single value or c(top, right, bottom, left).

zoomable

logical or numeric or character. Optional. Enables zoom interaction. Can define zoom extent or use "versor" for spherical zoom.

control

logical or numeric vector. Optional. Adds zoom control panel and optionally defines its position by using a vector of 2 values.

warning

logical. Optional. Whether to display warnings on the map (default TRUE).

Examples

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

viz_create(projection = "EqualEarth", zoomable = TRUE) |>
viz_path(data = world, fill = "#38896F") |>
viz_render()