I would like to animate a grouped barplot, such that each series is plotted in turn and then remains visible. In the example plot below I would like the bars with id = 1 to be plotted first and remain while id = 2, id = 3, id = 4 are plotted in turn.
df <- data.frame(id = factor(c(1:4)),
var1 = c(0, 20,60, 80),
var2 = c(18, 64, 91, 100),
var3 = c(8, 73, 100, 100),
var4 = c(18, 48, 67, 85))
df_melt <- melt(df, id.var = "id")
df_melt <- df_melt %>% mutate(show_time = 1, reveal_time = cumsum(show_time))
ggplot(data = df_melt, aes(x = variable, y = value, fill = id)) +
geom_bar(stat = "identity", position = "dodge")
I have been able to generate animated line plots using transition_reveal as described here: https://www.datanovia.com/en/blog/gganimate-how-to-create-plots-with-beautiful-animation-in-r/
I have tried using transition_reveal and transition_states (alone and in combination) in order to accomplish my goal, but so far have been unsuccessful. For example: transition_states(id).
I have also tried adding a reveal_time column to my data and using transition_reveal(reveal_time) to no avail.
All the animations I generate plot the values for id = 2 on top of id = 1 rather than to the side. As such, the final frame is a barplot with four bars rather than four groups of four.
Any help would be much appreciated - thanks!