Skip to content

Instantly share code, notes, and snippets.

@jebyrnes
Created February 20, 2019 05:11
Show Gist options
  • Save jebyrnes/8a45ad5ae5b06b0b1653bcede55ccf14 to your computer and use it in GitHub Desktop.
Save jebyrnes/8a45ad5ae5b06b0b1653bcede55ccf14 to your computer and use it in GitHub Desktop.
crossfading between raster layers in gganimate
library(ggplot2)
library(gganimate)
mygridstart <- tidyr::crossing(x = 1:10, y = 1:10)
mygrid <- rbind(mygridstart, mygridstart, mygridstart)
mygrid$rep <- sort(rep(1:3, nrow(mygrid)/3))
mygrid$pointgroup <- rep(1:100, 3)
mygrid$f <- factor(sample(1:3, replace=TRUE, size = nrow(mygrid)))
ggplot(mygrid,
aes(x = x, y = y, color = f, fill = f, group = pointgroup)) +
geom_raster() +
transition_states(rep) +
enter_fade() +
exit_fade()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment