title: How does gganimate order an ordered bar time-series?
body: <p>I have a time-series of data, where I'm plotting diagnosis rates for a disease on the y-axis <code>DIAG_RATE_65_PLUS</code>, and geographical groups for comparison on the x-axis <code>NAME</code> as a simple bar graph. My time variable is <code>ACH_DATEyearmon</code>, which the animation is cycling through as seen in the title.</p>
  
  <pre><code>df %&gt;% ggplot(aes(reorder(NAME, DIAG_RATE_65_PLUS), DIAG_RATE_65_PLUS)) +
    geom_bar(stat = "identity", alpha = 0.66) +
    labs(title='{closest_state}') +
    theme(plot.title = element_text(hjust = 1, size = 22),
          axis.text.x=element_blank()) +
    transition_states(ACH_DATEyearmon, transition_length = 1, state_length = 1) +
    ease_aes('linear')
  </code></pre>
  
  <p>I've reordered <code>NAME</code> so it gets ranked by <code>DIAG_RATE_65_PLUS</code>. </p>
  
  <p>What gganimate produces:</p>
  
  <p><a href="https://i.stack.imgur.com/GzcaT.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/GzcaT.gif" alt="gganimate plot"></a></p>
  
  <p>I now have two questions:</p>
  
  <p>1) How exactly does gganimate reorder the data? There is some overall general reordering, but each month has no frame where the groups are perfectly ordered by <code>DIAG_RATE_65_PLUS</code> from smallest to biggest. Ideally, I would like the final month "Aug 2018" to be ordered perfectly. All of the previous months can have their x-axis based on the ordered <code>NAME</code> for "Aug 2018`.</p>
  
  <p>2) Is there an option in gganimate where the groups "shift" to their correct rank for each month in the bar chart?</p>
  
  <p>Plots for my comment queries:</p>
  
  <p><a href="https://i.stack.imgur.com/s2UPw.gif" rel="noreferrer">https://i.stack.imgur.com/s2UPw.gif</a>
  <a href="https://i.stack.imgur.com/Z1wfd.gif" rel="noreferrer">https://i.stack.imgur.com/Z1wfd.gif</a></p>
  
  <p><strong>@JonSpring</strong></p>
  
  <pre><code>    df %&gt;%
    ggplot(aes(ordering, group = NAME)) +
    geom_tile(aes(y = DIAG_RATE_65_PLUS/2, 
                  height = DIAG_RATE_65_PLUS,
                  width = 0.9), alpha = 0.9, fill = "gray60") +
    geom_hline(yintercept = (2/3)*25, linetype="dotdash") +
    # text in x-axis (requires clip = "off" in coord_cartesian)
    geom_text(aes(y = 0, label = NAME), hjust = 2) + ## trying different hjust values
    theme(plot.title = element_text(hjust = 1, size = 22),
          axis.ticks.y = element_blank(), ## axis.ticks.y shows the ticks on the flipped x-axis (the now metric), and hides the ticks from the geog layer
          axis.text.y = element_blank()) + ## axis.text.y shows the scale on the flipped x-axis (the now metric), and hides the placeholder "ordered" numbers from the geog layer
    coord_cartesian(clip = "off", expand = FALSE) +
    coord_flip() +
    labs(title='{closest_state}', x = "") +
    transition_states(ACH_DATEyearmon, 
                      transition_length = 2, state_length = 1) +
    ease_aes('cubic-in-out')
  </code></pre>
  
  <p>With <code>hjust=2</code>, labels are not aligned and move around.</p>
  
  <p><a href="https://i.stack.imgur.com/yhJRN.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/yhJRN.gif" alt="enter image description here"></a></p>
  
  <p>Changing the above code with <code>hjust=1</code></p>
  
  <p><a href="https://i.stack.imgur.com/CS0tg.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/CS0tg.gif" alt="enter image description here"></a></p>
  
  <p><strong>@eipi10</strong></p>
  
  <pre><code>df %&gt;% 
    ggplot(aes(y=NAME, x=DIAG_RATE_65_PLUS)) +
    geom_barh(stat = "identity", alpha = 0.66) +
    geom_hline(yintercept=(2/3)*25, linetype = "dotdash") + #geom_vline(xintercept=(2/3)*25) is incompatible, but geom_hline works, but it's not useful for the plot
    labs(title='{closest_state}') +
    theme(plot.title = element_text(hjust = 1, size = 22)) +
    transition_states(ACH_DATEyearmon, transition_length = 1, state_length = 50) +
    view_follow(fixed_x=TRUE) +
    ease_aes('linear')
  </code></pre>