rep_geom: Repeat geom changing a small set of values

View source: R/rep_geom.R

rep_geomR Documentation

Repeat geom changing a small set of values

Description

Helper to repeat a geom multiple times swapping in different columns or constant values. Useful for things like drawing a white underdrawing beneath a layer.

Usage

rep_geom(geom_call, ...)

Arguments

geom_call

A geom layer with an aesthetics mapping.

...

A named series of values to use for aesthetic mappings.

Value

list of geoms

Examples

## Not run: 

rep_geom(geom_line(aes(x = x, y = y),
         linewidth = c(3, 1),
         color = c("white", color_group)))

# == is the same as ==>

list(
  geom_line(aes(x = x, y = y), linewidth = 3, color = "white"),
  geom_line(aes(x = x , y = y, color = color_grp), linewidth = 3)
)


# color is recycled to the length of the other aesthetics
ggplot(mtcars, aes(x = drat, y = mpg)) +
  rep_geom(geom_point(shape = 21),
           size = c(8, 6, 2),
           fill = c("gray80", am, "red"),
           color = "yellow")

# use !! when passing a variable containing a constant value
foo <- "green"
ggplot(mtcars, aes(x = drat, y = mpg)) +
  rep_geom(geom_point(shape = 21),
           size = c(8, 6, 2),
           fill = c(!!foo, am, "red"), # <- just passing foo won't work
           color = "yellow")
           
## End(Not run)

tsostarics/sostools documentation built on June 1, 2025, 10:20 p.m.