This is a variant of
transition_states() that is intended for data where
the states are representing specific point in time. The transition length
between the states will be set to correspond to the actual time difference
An unquoted expression giving the time, and thus state membership, of each observation.
The time range to animate. If
transition_time makes the following variables available for string
literal interpretation, in addition to the general ones provided by
frame_time gives the time that the current frame corresponds to
transition_time uses the group aesthetic of each layer to identify
which rows in the input data correspond to the same graphic element and will
therefore define which elements will turn into each other between time points.
The group aesthetic, if not set, will be calculated from the interaction of all
discrete aesthetics in the layer (excluding
label), so it is often better
to set it explicetly when animating, to make sure your data is interpreted in
the right way. If the group aesthetic is not set, and no discrete aesthetics
exists then all rows will have the same group. If the group aesthetic is not
unique in each state, then rows will be matched first by group and then by
index. Unmatched rows will appear/disappear, potentially using an enter or
It is possible to use variables calculated by the statistic to define the
transition. Simply inclose the variable in
stat() in the same way as when
using computed variables in aesthetics.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
anim <- ggplot(airquality, aes(Day, Temp)) + geom_point(aes(colour = factor(Month))) + transition_time(Day) # Removing a time point will prolong the tweening between neighbouring time # points so the time dimension stays linear airquality_missing <- airquality[airquality$Day <= 10 | airquality$Day >= 20, ] anim1 <- ggplot(airquality_missing, aes(Day, Temp)) + geom_point(aes(colour = factor(Month))) + transition_time(Day) # Range can be constrained if needed anim2 <- ggplot(airquality, aes(Day, Temp)) + geom_point(aes(colour = factor(Month))) + transition_time(Day, range = c(10L, 20L)) # The group aesthetic is used to connect elements # No grouping anim3 <- ggplot(airquality, aes(Day, Temp)) + geom_line() + transition_time(Month) # Group by month anim4 <- ggplot(airquality, aes(Day, Temp)) + geom_line(aes(group = Month)) + transition_time(Month) + enter_fade() + exit_fade()
Loading required package: ggplot2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.