title: gganimate: How to make stacked bar chart grow smoothly upwards from x-axis
body: <p>I'm having trouble animating a stacked static plot. (See animation below)</p>
  
  <p>The animation moves in a volatile way from left to right, instead of each bar growing upwards from the x-axis. The stacked parts also don't grow very smoothly together, which I can't seem to solve.</p>
  
  <p>What do I need to change in my code, so that, as the animated plot transitions along the x-axis, the individual bars grow upwards? I would also like to have the stacked bars grow more smoothly, so the stacked bar parts aren't "thrown" on top of each other.</p>
  
  <p>How is that possible?</p>
  
  <p>The top gif in this article is what I'm looking for, but I don't understand how and where his code differs from mine: <a href="https://twitter.com/ASpannbauer/status/940981263246221312" rel="nofollow noreferrer">ideal animation</a></p>
  
  <p>Here is my reprex:</p>
  
  <pre><code>#Static df
  library(dplyr)
  #&gt; 
  #&gt; Attaching package: 'dplyr'
  #&gt; The following objects are masked from 'package:stats':
  #&gt; 
  #&gt;     filter, lag
  #&gt; The following objects are masked from 'package:base':
  #&gt; 
  #&gt;     intersect, setdiff, setequal, union
  year &lt;- as.numeric(c(1996:2015,
                         1996:2015,
                         1996:2015))
  c &lt;- c(39, 40, 67, 80, 30, 140, 90, 23, 100, 123,
         140, 160, 100, 89, 173, 200, 32, 90, 100, 211,
         1, 2, 1, 13, 3, 3, 30, 1, 3, 3,
         1, 1, 20, 2, 1, 10, 1, 2, 1, 1,
         1, 3, 1, 2, 1, 3, 1, 3, 6, 1,
         1, 30, 1, 1, 8, 9, 1, 32, 1, 1)
  cat &lt;- as.character(c("out", "out", "out", "out", "out", "out", "out", "out", "out", "out",
                     "out", "out", "out", "out", "out", "out", "out", "out", "out", "out",
                     "in", "in", "in", "in", "in", "out", "in", "in", "in", "in",
                     "in", "in", "in", "in", "in", "in", "in", "in", "in", "in",
                     "other", "other", "other", "other", "other", "other", "other", "other", "other", "other",
                     "other", "other", "other", "other", "other", "other", "other", "other", "other", "other"))
  cat &lt;- as.factor(cat)
  static_df_test &lt;- data.frame(year, c, cat) %&gt;%
    select(year, cat, c) %&gt;%
    arrange(year, cat)
  
  
  #Static plot
  library(ggplot2)
  (static_plot &lt;- ggplot(static_df_test) +
      geom_bar(data = static_df_test, stat="identity", position ="stack",
               aes(x = year, y = c, fill = cat)) +
      scale_x_continuous(breaks = seq(1996, 2015, 1),
                         expand = c(0.003, 0.003),
                         labels = c(1996, 97, 98, 99, 2000,
                                    "01", "02", "03", "04", "05", "06",
                                    "07", "08", "09", 10, 11, 12, 13, 14, 15)) +
      scale_y_continuous(breaks = seq(0, 250, 25),
                         expand = c(0,0),
                         limits = c(0,250)) +
      labs(x = "year", y = "c")
  )
  
  #Animated plot
  library(gganimate)
  library(ggplot2)
  ani &lt;- (static_plot) +
    transition_time(as.integer(year)) +
    enter_grow() + shadow_mark(past = TRUE)
  
  animate(ani, fps = 8, 50, duration = 15,
          width = 1500, height = 750, renderer = gifski_renderer())
  </code></pre>
  
  <p>Right now, the bars transition by moving rightwards off of the previous bar. See the current animation here:  <a href="https://i.stack.imgur.com/AtqJN.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AtqJN.gif" alt="Current animation"></a></p>
  
  <p>Thank you in advance for any help!</p>