I have the following data frame:
# Seed RNG
set.seed(33550336)
# Create data frame
df <- data.frame(x = runif(100),
y = runif(100),
t = runif(100, min = 0, max = 10))
I'd like to plot points (i.e., at x
and y
coordinates) appearing and disappearing as a function of t
. gganimate
is awesome, so I used that.
# Load libraries
library(gganimate)
library(ggplot2)
# Create animation
g <- ggplot(df, aes(x = x, y = y))
g <- g + geom_point(colour = "#FF3300", shape = 19, size = 5, alpha = 0.25)
g <- g + labs(title = 'Time: {frame_time}')
g <- g + transition_time(t)
g <- g + enter_fade() + exit_fade()
animate(g, fps = 1)
This code produced the following:
There are a couple of things that I don't like about this.
- The transitions are very abrupt. My hope using
enter_fade
andexit_fade
was that the points would fade into view, then back out. Clearly this isn't the case, but how would I achieve this result? - I would like to round
{frame_time}
, so that while the points fade in and out at fractions oft
, the actual timet
that would be shown would be an integer. Ifframe_time
was a regular variable, this would be simple enough using something likebquote
andround
, but this doesn't seem to be the case. How can I roundframe_time
in my title?