Declare the scale for a mapped (discrete) shape aesthetic. Levels cycle
through a default set of marker shapes unless values is given. A shape legend
is drawn automatically.
Usage
scale_shape(
plot,
values = NULL,
name = NULL,
breaks = NULL,
labels = NULL,
limits = NULL,
na.value = NULL,
drop = TRUE
)
scale_shape_manual(
plot,
values,
breaks = NULL,
labels = NULL,
name = NULL,
limits = NULL,
na.value = NULL,
drop = TRUE
)
scale_shape_discrete(
plot,
values = NULL,
name = NULL,
breaks = NULL,
labels = NULL,
limits = NULL,
na.value = NULL,
drop = TRUE
)Arguments
- plot
A PlotSpec.
- values
Character vector of shapes, or
NULLfor the default. Each is either a built-in marker ("circle","square","triangle","diamond","plus","cross","triangle_down","star") or an SVG icon — a pathdstring (what icon sets ship) or a path to a.svgfile. SVG values are drawn as crisp vector markers (viavellum::svg_grob()) and the legend shows the icon; thesizeaesthetic scales them.For
scale_shape_manual()valuesis required, and may also be ggplot2's numeric shape codes (16,17, ...), which map to the nearest marker. As in ggplot2, the open codes (0-14) draw an outline in the point colour, the solid ones (15-20) fill with it, and the bordered ones (21-25) fill withfillinside acoloroutline (unfilled when nofillis given). Of the solid codes, 15-18 have no outline and 20 is 2/3 the size of 19, as in ggplot2. Each code draws at R's size for it: the triangles are larger than the circle (equal in area), the bordered square (22) a little smaller than the open and solid ones, and so on. By name, these are"circle open","circle filled","circle bare"(no outline),"circle small"and so on for every built-in marker; the plain names ("triangle") keep vellum's own sizes. Named values are matched to levels by name.- name
Legend title, or
NULLto derive from the encoding.- breaks
The levels the legend shows (and their order), or
NULLfor all of them.- labels
Legend labels: one per shown level, a vector named by level, or a function of the levels;
NULLkeeps the levels.- limits
The levels the scale covers (a character vector), or
NULLfor the levels in the data. Data outsidelimitsdraws asna.value.- na.value
The shape drawn for missing values (default a circle).
- drop
For the discrete scales, drop factor levels that no row uses (default
TRUE, as in ggplot2): they get no legend key and no palette entry, so the colours go to the levels that remain.FALSEkeeps every level.limitsoverrides it.
Value
The modified PlotSpec.
Examples
vplot(mtcars) |> mark_point(x = wt, y = mpg, shape = factor(cyl))
# SVG icon markers, one per level:
star <- "M12 2l3 7h7l-5.5 4.5 2 7-6.5-4.5-6.5 4.5 2-7L2 9h7z"
vplot(mtcars) |>
mark_point(x = wt, y = mpg, shape = factor(cyl)) |>
scale_shape(values = c(star, star, star))
vplot(mtcars) |>
mark_point(x = wt, y = mpg, shape = factor(cyl)) |>
scale_shape_manual(values = c("4" = 16, "6" = 17, "8" = 15))
