Pipable ggplot2 geoms
geom_.Rd
A ggplot2::layer()
containing a ggplot2::Geom; intended for piping.
Usage
geom_(x, ...)
# S3 method for character
geom_(x, ...)
# S3 method for ggbuilder_layer
geom_(x, ...)
# S3 method for ggbuilder_layer_spec
geom_(x, ...)
# S3 method for ggbuilder_plot_data
geom_(x, ...)
Arguments
- x
One of:
A string: The suffix of a
geom_XXX
function used to create this geom.A ggbuilder layer, layer_spec, or plot_data object representing earlier data and data transformations used as input to this geom. In this case, the second argument should be the suffix of a
geom_XXX
function used to create this geom.
- ...
arguments passed on to the geom's constructor.
Value
A ggbuilder layer, which is also a ggplot2::layer, and which can be
added to a ggplot()
object or piped into other ggbuilder functions.
Details
geom_()
can be used to replace typical geom_XXX()
calls in ggplot2
code to make them pipable by using the XXX
suffix as a string as the first
argument to geom_()
.
For example, geom_boxplot(...)
would become geom_("boxplot", ...)
.
The primary difference between the former and the latter is that the latter
is both a ggplot2::layer and a ggbuilder layer containing a layer_spec.
The contained layer_spec stores information on how to construct the
geom, which allows it to be combined with other objects (e.g. by piping it
into remap()
) to construct more complex layers. See Examples.
Examples
library(ggplot2)
set.seed(123456)
df = data.frame(condition = c("A", "B", "C"), response = round(rnorm(30, 1:3), 1))
df |>
ggplot(aes(x = condition, y = response, color = condition)) +
geom_boxplot() +
stat_("boxplot", aes(y = response)) |>
geom_("label", aes(y = ymax, label = ymax)) |>
remap(aes(fill = scales::alpha(color, 0.1))) +
theme_light()
#> Warning: Duplicated aesthetics after name standardisation: NA
#> Warning: Duplicated aesthetics after name standardisation: NA