R/shadow-.R

Defines functions ggplot_add.Shadow

#' @rdname gganimate-ggproto
#' @format NULL
#' @usage NULL
#' @export
#' @importFrom ggplot2 ggproto
Shadow <- ggproto('Shadow', NULL,
  exclude_layer = integer(0),
  params = list(),
  setup_params = function(self, data, params) {
    params
  },
  train = function(self, data, params) {
    params
  },
  get_frames = function(self, params, i) {
    integer(0)
  },
  prepare_shadow = function(self, shadow, params) {
    lapply(shadow, do.call, what = rbind)
  },
  prepare_frame_data = function(self, data, shadow, params, frame_ind, shadow_ind) {
    Map(function(d, s, e) {
      if (e) return(d[[1]])
      rbind(s, d[[1]])
    }, d = data, s = shadow, e = seq_along(data) %in% params$excluded_layers)
  }
)
#' @importFrom ggplot2 ggplot_add
#' @export
ggplot_add.Shadow <- function(object, plot, object_name) {
  plot <- as.gganim(plot)
  plot$shadow <- object
  plot
}

Try the gganimate package in your browser

Any scripts or data that you put into this service are public.

gganimate documentation built on Sept. 8, 2022, 5:09 p.m.