The viz_leg_gradient_vertical function creates a vertical gradient legend.
It draws a series of colored rectangles with three labels aligned at top,
middle, and bottom. The function adds a legend layer to the map.
Usage
viz_leg_gradient_vertical(
map,
id = NULL,
pos = c(0, 0),
gap = 5,
colors = c("#fee5d9", "#fcae91", "#fb6a4a", "#cb181d"),
rect_width = 8,
rect_height = 25,
rect_spacing = 0,
rect_stroke = "white",
values_fontSize = 12,
values_fill = "black",
text_high = "High",
text_intermediate = "Intermediate",
text_low = "Low",
reverse = FALSE,
frame = FALSE,
...
)Arguments
- map
A
geovizobject created withviz_create.- id
character. Optional. ID of the layer.
- pos
numeric vector of length 2. Optional. Position of the legend (default c(0, 0)).
- gap
numeric. Optional. Gap between title/subtitle and rectangles (default 5).
- colors
character vector. Optional. Colors of the gradient (default c("#fee5d9", "#fcae91", "#fb6a4a", "#cb181d")).
- rect_width
numeric. Optional. Rectangle width (default 8).
- rect_height
numeric. Optional. Rectangle height (default 25).
- rect_spacing
numeric. Optional. Spacing between rectangles (default 0).
- rect_stroke
character. Optional. Stroke color of rectangles (default "white").
- values_fontSize
numeric. Optional. Font size of labels (default 12).
- values_fill
character. Optional. Label color (default "black").
- text_high
character. Optional. Label at top (default "High").
- text_intermediate
character. Optional. Label at middle (default "Intermediate").
- text_low
character. Optional. Label at bottom (default "Low").
- reverse
logical. Optional. Reverse the order of colors (default FALSE).
- frame
logical. Optional. Draw a frame around the legend (default FALSE).
- ...
Additional SVG attributes passed to elements.
Examples
library(sf)
world <- st_read(
system.file("gpkg/world.gpkg", package = "geoviz"),
quiet = TRUE
)
viz_create(projection = "EqualEarth", background = "white") |>
viz_path(datum = world, fill = "#f1f3f5") |>
viz_leg_gradient_vertical(pos = c(20, 20)) |>
viz_render()