The viz_prop function creates a proportional symbol layer
from a spatial data frame. It can display different symbol types (circle, square,
spike, half-circle) sized according to a numeric variable, and optionally includes
a legend.
Usage
viz_prop(
map,
data = NULL,
var,
symbol = "circle",
k = 50,
fixmax = NULL,
width = 30,
straight = 0,
dodge = FALSE,
legend = TRUE,
leg_type = "nested",
leg_pos = c(10, 10),
...
)Arguments
- map
A
geovizmap created withviz_create.- data
A spatial dataframe
- var
character. Variable name containing numeric values used for scaling symbols.
- symbol
character. Optional. Symbol type (default "circle"). One of: "circle", "square", "spike", "halfcircle".
- k
numeric. Optional. Size of the largest symbol (default 50).
- fixmax
numeric. Optional. Value corresponding to the symbol of size
k. Useful to ensure comparability between maps.- 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).
- dodge
logical. Optional. Avoid symbol overlap (default FALSE, circle only).
- legend
logical. Optional. Whether to display a legend (default TRUE).
- leg_type
character. Optional. Legend type (default "nested"). One of: "nested", "separate".
- leg_pos
numeric vector. Optional. Legend position (default c(10, 10)).
- ...
Additional parameters passed to symbol rendering (e.g.
strokeWidth). With theleg_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_path(
datum = world, fill = "#f1f3f5"
) |>
viz_prop(
data = world, var = "pop", symbol = "circle", fill = "#38896F",
k = 25, leg_values_round = 0, leg_title = "Population",
leg_subtitle = "(million inh.)", leg_values_factor = 1 / 1000000
) |>
viz_render()