Skip to contents

The viz_spike function draws spikes on the map from a spatial data frame or from a single position. It can be used to represent values with vertical symbols (e.g. for density or intensity maps).

Usage

viz_spike(
  map,
  data = NULL,
  id = NULL,
  pos = c(0, 0),
  height = 10,
  width = 30,
  straight = 0,
  k = 100,
  fixmax = NULL,
  sort = NULL,
  descending = NULL,
  coords = "geo",
  fill = NULL,
  stroke = NULL,
  tip = FALSE,
  ...
)

Arguments

map

A geoviz map created with viz_create.

data

object. Optional. A spatial data frame.

id

character. Optional. Unique layer id.

pos

numeric vector. Optional. Position of a single spike (default c(0, 0)).

height

numeric or character. Optional. Spike height (default 10). Can be a fixed value or the name of a field containing numerical values.

width

numeric. Optional. Spike width (default 30).

straight

numeric. Optional. Controls spike curvature (default 0). Value between 0 (curved) and 1 (straight).

k

numeric. Optional. Height of the highest spike (default 100).

fixmax

numeric. Optional. Value corresponding to the spike of height k. Useful to ensure comparability between maps.

sort

character or function. Optional. Field name or function to sort spikes.

descending

logical. Optional. Sorting order.

coords

character. Optional. Coordinate system (default "geo"). Use "svg" if coordinates are already expressed in the SVG coordinate space.

fill

character or function. Optional. Fill color.

stroke

character or function. Optional. Stroke color.

tip

logical or function. Optional. Tooltip definition (default FALSE). Use TRUE to display all fields.

...

Additional SVG attributes (e.g. strokeDasharray, strokeWidth, opacity, strokeLinecap, etc.).

Examples

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

viz_create(projection = "EqualEarth") |>
viz_path(datum = world, fill = "#f1f3f5") |>
viz_square(data = world, height = 100, fill = "#38896F") |>
viz_render()