Skip to contents

The viz_propchoro function combines proportional symbols and choropleth mapping on the same spatial data frame. It allows simultaneous encoding of two numeric variables using symbols (size) and colors (classification).

Usage

viz_propchoro(
  map,
  data = NULL,
  var1,
  var2,
  var = NULL,
  symbol = "circle",
  k = 50,
  fixmax = NULL,
  dodge = FALSE,
  width = 30,
  straight = 0,
  method = "quantile",
  nb = 6,
  breaks = NULL,
  colors = NULL,
  middle = FALSE,
  sd = 1,
  reverse = FALSE,
  missing = "white",
  legend = TRUE,
  leg1_type = "nested",
  leg2_type = "vertical",
  leg1_pos = c(10, 10),
  leg2_pos = NULL,
  ...
)

Arguments

map

A geoviz map created with viz_create.

data

A spatial dataframe Use data to enable iteration over features.

var1

character. Name of the numeric variable used for absolute values (driving symbol size).

var2

character. Name of the numeric variable used for relative values (driving color classification, e.g. percentages).

var

character. Optional. If provided, the same variable is used for both size and color encoding.

symbol

character. Optional. Symbol type (default "circle"). One of: "circle", "spike", "halfcircle".

k

numeric. Optional. Size of the largest symbol (default 50).

fixmax

numeric. Optional. Value corresponding to the symbol of size k. Useful for ensuring comparability between maps.

dodge

logical. Optional. Avoid symbol overlap (default FALSE, circle only).

width

numeric. Optional. Width of spike symbols (default 30).

straight

numeric. Optional. Curvature of spike symbols (default 0). Value between 0 (curved) and 1 (straight).

method

character. Optional. Classification method for choropleth (default "quantile"). One of: "quantile", "q6", "equal", "jenks", "msd", "geometric", "headtail", "pretty", "arithmetic", "nestedmeans".

nb

numeric. Optional. Number of classes (default 6).

breaks

numeric vector. Optional. Manual class breaks overriding nb and method.

colors

character or vector. Optional. Color palette or vector of colors from the Dicopal library. See https://observablehq.com/@neocartocnrs/dicopal-library

middle

logical. Optionnal Only for the MSD method: is the mean in a central class or not? (default FALSE)

sd

number. Only for the MSD method: the number of standard deviations taken into account (default 1)

reverse

logical. Optional. Reverse color palette (default FALSE).

missing

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

legend

logical. Optional. Whether to display legends (default TRUE).

leg1_type

character. Optional. Symbol legend type (default "nested").

leg2_type

character. Optional. Choropleth legend type (default "vertical").

leg1_pos

numeric vector. Optional. Position of symbol legend (default c(10, 10)).

leg2_pos

numeric vector. Optional. Position of choropleth legend.

...

Additional parameters passed to rendering functions (e.g. strokeWidth). With leg1_ and leg2_ prefixes, you can configure the legends. For example: leg1_title, leg2_subtitle, leg1_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_path(
  datum = world, fill = "#f1f3f5"
) |>
viz_propchoro(
  data = world, var1 = "pop", k = 25,
  leg1_values_round = 0, var2 = "gdppc",
  leg1_title = "Population",
  leg1_subtitle = "(million inh.)",
  leg1_values_factor = 1 / 1000000,
  leg2_values_round = 0,
  leg2_title = "GDP per inh.",
  colors = "Temps"
) |>
viz_render()