title: Formatting dates for {closest_state} output in r (bar chart race)
body: <p>In this bar chart race, with a Y-m-d date format (&quot;2010-11-30… etc&quot;), the gif (<em>below</em>) runs through the dates fine...</p>
  <p><a href="https://i.stack.imgur.com/vMlIl.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vMlIl.gif" alt="enter image description here" /></a></p>
  <p>...but when I convert those same dates to a %Y %b format (&quot;2010 Nov… etc&quot;), months are missing throughout the animation, as shown in this second gif, <em>below</em></p>
  <p><a href="https://i.stack.imgur.com/OWuel.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OWuel.gif" alt="enter image description here" /></a></p>
  <p>Furthermore, I’d ideally like the date to be displayed as %b %Y format (Nov 2010… etc). I've spent weeks trying to sort this out but to no avail. Any help would be appreciated.</p>
  <p>Here's the code</p>
  <pre><code>df &lt;- read.csv(file=&quot;Data/Carmakers market caps monthly.csv&quot;)
  
  # Renames headings
  df&lt;-rename(df, c(General.Motors = &quot;General Motors&quot;, Toyota.Motor = &quot;Toyota Motor&quot;))
  
  
  meltdf &lt;- melt(df,id=&quot;Date&quot;)
  names(meltdf) &lt;- c(&quot;Date&quot;, &quot;Company&quot;, &quot;Value&quot;)
  
  
  meltdf$Date &lt;- as.Date(meltdf$Date, &quot;%d/%m/%Y&quot;)
  
  
  meltdf$Value &lt;- as.numeric(as.character(meltdf$Value))
  
  meltdf = meltdf %&gt;% 
    group_by(Date)%&gt;%      
    mutate(rank = rank(-Value),
           Value_rel = Value/Value[rank==1],
           Value_lbl = paste0(&quot; &quot;,Value/1000000000)) %&gt;%
    group_by(Company)
  
  
  meltdf$Value_lbl &lt;- as.numeric(as.character(meltdf$Value_lbl))
  
  meltdf$Value &lt;- as.numeric(as.character(meltdf$Value/1000000000))
  
  meltdf$Value_lbl &lt;- sprintf(meltdf$Value_lbl, fmt = '%#.1f')
  
  strftime(meltdf$Date, format = &quot;%Y %b&quot;) -&gt; 
    meltdf$Date
  
  
  #plotting graph
  anim &lt;-ggplot(meltdf,aes(rank,
                              group=Company,
                              fill=as.factor(Company),
                              color=as.factor(Company))) +
    geom_tile(aes(y = Value/2,
                  height = Value,
                  width = 0.9), alpha = 0.8, color = NA) +
    geom_text(aes(y = 0, label = paste(Company, &quot; &quot;)), vjust = 0.2, hjust = 1)+
    geom_text(aes(y=Value,label = Value_lbl, hjust=0)) +
    coord_flip(clip = &quot;off&quot;, expand = TRUE) +
    scale_y_continuous(labels = scales::comma) +
    scale_x_reverse() +
    guides(color = FALSE, fill = FALSE) +
    theme_minimal() +
    theme(
      plot.title=element_text(size=23, hjust=0.5, face=&quot;bold&quot;, colour=&quot;grey&quot;, vjust=-1),
      plot.subtitle=element_text(size=18, hjust=0.5, face=&quot;italic&quot;, color=&quot;grey&quot;, 
  margin = margin(t = 15, r = 0, b = 0, l = 0)),
      plot.caption =element_text(size=8, hjust=0.5, face=&quot;italic&quot;, color=&quot;grey&quot;),
      axis.ticks.y = element_blank(), 
      axis.text.y = element_blank(), 
      plot.margin = margin(1,1,1,2, &quot;cm&quot;)) +
    transition_states(states = Date, transition_length = 12, state_length = 1, wrap = FALSE) + 
    ease_aes('cubic-in-out') +
    #view_follow(fixed_x = TRUE) +
    labs(title = 'Largest car companies in the world {closest_state}', 
         subtitle = &quot;Market capitalization&quot;,
         caption = &quot;Data source: Refinitiv&quot;,
         x=&quot;&quot;, y=&quot;$ billion&quot;)
  
  #Create gif
  animate(anim, nframes = 400,fps = 8.1,  width = 550, height = 350,
          renderer = gifski_renderer(&quot;car_companies_2.gif&quot;), end_pause = 15, start_pause =  25)
  
  </code></pre>
  <p>And here's a sample of the data that created this chart.</p>
  <pre><code>        Date      Tesla Toyota Motor General Motors     Daimler
  1 30/11/2010 3295253866 132694537161    51300000000 52944591823
  2 31/12/2010 2483798768 136160803584    55290000000 53967411400
  3  31/1/2011 2247823894 142843809831    54735000000 56926590672
  4  28/2/2011 2277562013 161097730179    52331714768 54401346072
  5  31/3/2011 2645556545 138915112426    48429857121 53122249064
  6  30/4/2011 2639462630 136650698149    50084659687 55615851126
  
  118  31/8/2020 464338876502 215889700906    42403389651 45497228943
  119  30/9/2020 399755220356 214500698099    42346145790 49249966873
  120 31/10/2020 367823400433 212138493292    49423051428 47500782647
  121 30/11/2020 538028456051 219024834051    62748525184 60564258296
  122 31/12/2020 668905110256 250711385128    59599648464 61825906062
  123  31/1/2021 668905110256 250711385128    59599648464 61825906062
  </code></pre>