title: R: gganimate with geom_density
body: <p>I am trying to create an animate graph with <code>gganimate</code>. My defaul graph, static is something like:<a href="https://i.stack.imgur.com/mnHUs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mnHUs.png" alt="enter image description here"></a></p>
  
  <p>But instead of 3 grouping variables I have 12 (year 0, year 1, year 2, etc.). Instead of plotting all 12 variables together I would like to animate it. To avoid:
  <a href="https://i.stack.imgur.com/ECx48.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ECx48.jpg" alt="enter image description here"></a> </p>
  
  <p>Those kernel densities plots are made as follows:</p>
  
  <pre><code>data_decidious %&gt;% tidyr::gather("YEAR", "NDVI", colsPostNDVI) %&gt;%    
    mutate(YEAR = str_remove(YEAR, 'meanNDVIyear')) %&gt;% mutate(YEAR = str_remove(YEAR, 'meanprefire_NDVI')) %&gt;% mutate(YEAR = as.factor(YEAR)) %&gt;%    
    ggplot(aes(NDVI,fill=YEAR)) + geom_density(alpha=.2) + xlim(0.3, 0.7) + ylim(0,46) +
    xlab("Mean NDVI") + ylab("Kernal density") + guides(fill=guide_legend(title="Comparative"))
  </code></pre>
  
  <p>I have found that this <code>geom_density()</code> only works when I add <code>mutate(YEAR = as.factor(YEAR))</code>. That means when I add:</p>
  
  <pre><code>transition_time(YEAR) + ease_aes('linear')
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>Error: time data must either be integer, numeric, POSIXct, Date, difftime, orhms
  In addition: Warning message:
  In min(cl[cl != 0]) : no non-missing arguments to min; returning Inf
  </code></pre>
  
  <p>Any idea to animate my graph?</p>