Here is a reproducible example of a static plot, which I want to animate (I want to show how a MCMC sampler behaves).
library(tidyverse)
library(gganimate)
set.seed(1234)
plot_data <- tibble(x=cumsum(rnorm(100)),
y=cumsum(rnorm(100)),
time=1:length(x))
ggplot(data=plot_data,
aes(x=y, y=x)) +
geom_point() + geom_line()
What I'd like to see is the points being visible when they are drawn and a bit faded (i.e. alpha goes from e.g. 1 to 0.3) afterwards, while there would be a line that only shows the recent history (and ideally fades showing the most recent history the least faded and more than a few steps back totally disappearing).
The following achieves more or less what I want for my points (so in a sense I just want to add fading lines to this connecting the last few points - points fading more slowly across some frames would be even nicer):
ggplot(data=plot_data,
aes(x=y, y=x)) +
geom_point() +
transition_time(time) +
shadow_mark(past = T, future=F, alpha=0.3)
What I am struggling with is how to add two different behaviors for two geoms e.g. point and line. E.g. in the below the points disappear (I don't want them to) and the lines do not fade (I want them to).
p <- ggplot(data=plot_data,
aes(x=y, y=x)) +
geom_point() +
transition_time(time) +
shadow_mark(past = T, future=F, alpha=0.3)
p + geom_line() +
transition_reveal(along = time) +
shadow_mark(past = T, future=F, alpha=0.3)