Skip to contents

A layer operation for copying and then adjusting the params and aesthetic mappings of a layer-like object.


copy_over(object, mapping = aes(), ...)

copy_under(object, mapping = aes(), ...)



One of:

  • A layer-like object: applies this operation to the layer.

  • A missing argument: creates an operation

  • Anything else: creates an operation, passing object along to the mapping argument


An aesthetic created using aes(). Mappings provided here will overwrite mappings in ggplot2::layer()s when this operation is applied to them.


ggplot2::layer() parameters, such as would be passed to a geom_...() or stat_...() call. Params provided here will overwrite params in layers when this operation is applied to them.


A layer-like object (if object is layer-like) or an operation (if not).


These are shortcuts for duplicating a layer and then applying adjust(). Specifically:

  • copy_over(...) is equivalent to 1 + adjust(...)

  • copy_under(...) is equivalent to adjust(...) + 1

See also

operation for a description of layer operations.

Other layer operations: adjust, affine_transform, blend, nop, partition()



# here we use copy_under() to create a copy of
# the stat_smooth layer, putting a white outline around it.
k = 1000
  x = seq(1, 10, length.out = k),
  y = rnorm(k, seq(1, 2, length.out = k) + c(0, 0.5)),
  g = c("a", "b")
) |>
  ggplot(aes(x, y, color = g)) +
  geom_point() +
  stat_smooth(method = lm, formula = y ~ x, linewidth = 1.5, se = FALSE) *
    copy_under(aes(group = g), color = "white", linewidth = 4) +
  scale_color_brewer(palette = "Dark2")