The viz_square function draws rotatable squares on the map
from a spatial data frame or from a single position. It can be used to create
proportional symbol maps with square markers.
Usage
viz_square(
map,
data = NULL,
id = NULL,
pos = c(0, 0),
dx = 0,
dy = 0,
angle = 0,
side = 20,
k = 100,
fixmax = NULL,
sort = NULL,
descending = NULL,
coords = "geo",
fill = NULL,
stroke = NULL,
tip = FALSE,
...
)Arguments
- map
A
geovizmap created withviz_create.- data
object. Optional. A spatial data frame.
- id
character. Optional. Unique layer id.
- pos
numeric vector. Optional. Position of a single square (default c(0, 0)).
- dx
numeric. Optional. Horizontal shift (default 0).
- dy
numeric. Optional. Vertical shift (default 0).
- angle
numeric. Optional. Rotation angle in degrees (default 0).
- side
numeric or character. Optional. Square size (default 20). Can be a fixed value or the name of a field containing numerical values.
- k
numeric. Optional. Size of the largest square (default 100).
- fixmax
numeric. Optional. Value corresponding to the square of size
k. Useful to ensure comparability between maps.- sort
character or function. Optional. Field name or function to sort squares.
- 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, side = 60, fill = "#38896F") |>
viz_render()