shape_raw is the simplest drawable: the user supplies x and y
coordinates directly, and points is computed trivially from them.
It is most often produced by convert()ing a more complex drawable
(e.g. a shape_blob or shape_twist) down to its raw vertices.
shape_raws() is a vectorized version of shape_raw(). Since x/y
are themselves numeric vectors of vertex coordinates for a single
polygon, shape_raws() takes them as a list() of numeric vectors
instead – one vector of vertices per shape.
Usage
shape_raw(x, y, id = NULL, trans = trans_identity(), ...)
shape_raws(x, y, id = NULL, trans = trans_identity(), ...)Arguments
- x, y
For
shape_raw(), a numeric vector of x/y coordinates. Forshape_raws(), alist()of such vectors instead – one vector of vertices per shape.- id
For
shape_raw(), an integer vector the same length asx/y, orNULL(the default, a single sub-path). Forshape_raws(), alist()of such vectors (orNULLs) instead, one per shape.- trans
A trans object applied to the shape's computed points. Default
trans_identity()(no transform).- ...
Arguments passed to
style().
Details
id optionally groups x/y into multiple sub-paths (see xy's own
id) – several disjoint polygons sharing one style, or, combined
with style()'s rule, a shape with a hole. shape_combine() is a
more convenient way to build this from several already-built
drawables' own points, rather than computing id by hand.
Every other argument may be a plain vector, recycled against x/y
via purrr::pmap()'s own vctrs-based rules (any length-1 element is
broadcast to the common length; mismatched lengths greater than 1
raise an error). The result is a sketch containing one
shape_raw() per list element/recycled row, rather than a single
drawable.
Examples
draw(shape_raw(x = c(0, 1, 1, 0), y = c(0, 0, 1, 1)))
# any polygon can be "frozen" to a shape_raw by converting it
frozen <- S7::convert(
shape_blob(radius = 1, distortion = noise_field(seed = 5150)),
shape_raw
)
draw(frozen)
draw(shape_raw(
x = c(0, 1, 0.5), y = c(0, 0, 1),
fill = "goldenrod", color = "black", linewidth = 2
))
# id groups x/y into sub-paths -- here, a ring with a hole (a smaller
# sub-path nested inside a larger one, under style()'s default
# rule = "evenodd")
draw(shape_raw(
x = c(0, 0, 4, 4, 1, 1, 3, 3),
y = c(0, 4, 4, 0, 1, 3, 3, 1),
id = c(1, 1, 1, 1, 2, 2, 2, 2),
fill = "steelblue"
))
draw(shape_raws(
x = list(c(0, 1, 1, 0), c(2, 3, 3, 2)),
y = list(c(0, 0, 1, 1), c(0, 0, 1, 1))
))