I want to create an animated barplot with the gganimate
package. Below the barplot, I want to annotate a text box. The text within the box should change over time. The x-axis of the barplot should be moving (as specified by view_follow
). However, the text box should be shown at a fixed point of the plot.
Consider the following example:
# Create example data
df <- data.frame(ordering = c(rep(1:3, 2), 3:1, rep(1:3, 2)),
year = factor(sort(rep(2001:2005, 3))),
value = round(runif(15, 0, 100)),
group = rep(letters[1:3], 5))
library("gganimate")
library("ggplot2")
# Create animated ggplot with coord_flip
ggp <- ggplot(df, aes(x = ordering, y = value)) +
geom_bar(stat = "identity", aes(fill = group)) +
transition_states(year, transition_length = 2, state_length = 0) +
view_follow(fixed_x = TRUE) +
coord_flip() +
theme(axis.title.x = element_blank(),
axis.ticks.x = element_blank(),
axis.text.x = element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(),
plot.margin = unit(c(1, 1, 8, 1), "cm"))
Question: How could I annotate a text box with changing text in the white area below this plot?