scale_gshape_manual {ggalign} | R Documentation |
Scale for gshape
aesthetic
Description
geom_gshape
depends on the new aesthetics gshape
(shape with grid
functions), which should always be provided with scale_gshape_manual()
,
in which, we can provide a list of grobs or functions that define how each
value should be drawn. Any ggplot2 aesthetics can be used as the arguments.
Usage
scale_gshape_manual(..., values, breaks = waiver(), na.value = NA)
Arguments
... |
Arguments passed on to
|
values |
A list of grobs or functions (including purrr-like lambda syntax) that define how each cell's grob (graphical object) should be drawn. |
breaks |
One of:
|
na.value |
The aesthetic value to use for missing ( |
Life cycle
We're unsure whether this function is truly necessary, which is why it is
marked as questioning. So far, we've found that geom_subrect()
and
geom_subtile()
handle most use cases effectively.
Aesthetics
geom_gshape()
understands the following aesthetics (required aesthetics are in bold):
Learn more about setting these aesthetics in vignette("ggplot2-specs", package = "ggplot2")
.
Examples
library(grid)
ggplot(data.frame(value = letters[seq_len(5)], y = seq_len(5))) +
geom_gshape(aes(x = 1, y = y, gshape = value, fill = value)) +
scale_gshape_manual(values = list(
a = function(x, y, width, height, fill) {
rectGrob(x, y,
width = width, height = height,
gp = gpar(fill = fill),
default.units = "native"
)
},
b = function(x, y, width, height, fill) {
rectGrob(x, y,
width = width, height = height,
gp = gpar(fill = fill),
default.units = "native"
)
},
c = function(x, y, width, height, fill) {
rectGrob(x, y,
width = width, height = height,
gp = gpar(fill = fill),
default.units = "native"
)
},
d = function(x, y, width, height, shape) {
gList(
pointsGrob(x, y, pch = shape),
# To ensure the rectangle color is shown in the legends, you
# must explicitly provide a color argument and include it in
# the `gpar()` of the graphical object
rectGrob(x, y, width, height,
gp = gpar(col = "black", fill = NA)
)
)
},
e = function(xmin, xmax, ymin, ymax) {
segmentsGrob(
xmin, ymin,
xmax, ymax,
gp = gpar(lwd = 2)
)
}
)) +
scale_fill_brewer(palette = "Dark2") +
theme_void()