Update: Sorry I forgot to add the vector:
time=1:100
value = 1:67
fill = rep(max(value), 100-max(value))
I want to make an animated stacked bar, Here is my example:
library(tidyverse)
library(gganimate)
#example data frame
df <- tibble(time = time,
value = c(value, fill),
x = "A") %>%
mutate(fill_color = "gold") %>%
mutate(gold_nr = value) %>%
mutate(blue_nr = rev(gold_nr)) %>%
pivot_longer(c(gold_nr, blue_nr),
names_to = "color_group",
values_to = "value_group")
# the code:
p <- df %>%
ggplot(aes("", value_group, fill=color_group)) +
geom_col(width = 0.3, position = position_fill())+
scale_fill_manual(values = c("gold", "steelblue"))+
theme_minimal()+
# theme(legend.position="none")+
transition_manual(value)+
coord_flip()
animate(p, fps=24, renderer = gifski_renderer(loop = FALSE))
My question is: Why does the bar not stop at 67 and jumps over 75? I think I have to organize the data in a other way?