Skip to contents

The viz_typo function creates a typology map from a spatial data frame by mapping categorical variables to colors. It supports custom ordering, color palettes, and automatic legend generation.

Usage

viz_typo(
  map,
  data = NULL,
  var,
  colors = NULL,
  order = NULL,
  alphabetical = TRUE,
  missing = "white",
  legend = TRUE,
  leg_type = "vertical",
  leg_pos = c(10, 10),
  ...
)

Arguments

map

A geoviz map created with viz_create.

data

A spatial dataframe Use data to enable iteration over features.

var

character. Name of the categorical variable used for styling. You can also use fill or stroke directly instead of var.

colors

character or vector. Optional. Color palette or vector of colors. Can use named palettes from the Dicopal library (e.g. "Antique", "Bold", "Pastel", "Prism", "Safe", "Vivid", "Accent", "Dark2", "Paired", "Pastel1", "Pastel2", "Set1", "Set2", "Set3"). See https://observablehq.com/@neocartocnrs/dicopal-library

order

character vector. Optional. Explicit ordering of categories.

alphabetical

logical. Optional. Whether to sort legend items alphabetically (default TRUE).

missing

character or logical. Optional. Color for missing values (default "white").

legend

logical. Optional. Whether to display a legend (default TRUE).

leg_type

character. Optional. Legend orientation (default "vertical"). One of: "horizontal", "vertical".

leg_pos

numeric vector. Optional. Legend position (default c(10, 10)).

...

Additional parameters passed to path rendering. With the leg_ prefix, you can configure the legend. For example: leg_title, leg_subtitle, leg_note, etc.

Examples

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

viz_create(
  projection = "EqualEarth", background = "white",
  zoomable = TRUE
) |>
viz_typo(
  data = world, var = "region", colors = "Pastel",
  leg_title = "Continents"
) |>
viz_render()