<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>gganimate | B101nfo</title>
    <link>https://llrs.dev/tags/gganimate/</link>
      <atom:link href="https://llrs.dev/tags/gganimate/index.xml" rel="self" type="application/rss+xml" />
    <description>gganimate</description>
    <generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><copyright>If it is code you can copy and reuse (MIT) if it is text, please cite and reuse CC-BY 2024.</copyright><lastBuildDate>Fri, 24 May 2019 00:00:00 +0000</lastBuildDate>
    <image>
      <url>img/map[gravatar:%!s(bool=false) shape:circle]</url>
      <title>gganimate</title>
      <link>https://llrs.dev/tags/gganimate/</link>
    </image>
    
    <item>
      <title>Forest fires in Mexico</title>
      <link>https://llrs.dev/post/2019/05/24/fires-mexico/</link>
      <pubDate>Fri, 24 May 2019 00:00:00 +0000</pubDate>
      <guid>https://llrs.dev/post/2019/05/24/fires-mexico/</guid>
      <description>
&lt;script src=&#34;https://llrs.dev/post/2019/05/24/fires-mexico/index_files/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;


&lt;div id=&#34;evolucion-de-los-incendios-forestales-en-méxico&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Evolucion de los incendios forestales en México&lt;/h2&gt;
&lt;p&gt;I saw a map on twitter and I wanted to see if I could change a bit and improve it:&lt;/p&gt;

&lt;p&gt;I wanted to make so that the fires change the size with time to appear and disappear instead of moving around Mexico.&lt;/p&gt;
&lt;p&gt;I got the &lt;a href=&#34;https://github.com/bautista-adrian/Incendios_Mx/blob/master/Incendios.R&#34;&gt;code from Andrian&lt;/a&gt;, I ran the code and stored it:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(&amp;quot;here&amp;quot;)
## here() starts at /home/lluis/Documents/Projects/blogR
library(&amp;quot;ggplot2&amp;quot;)
library(&amp;quot;gganimate&amp;quot;)
library(&amp;quot;ggthemes&amp;quot;)
# Maps from mexico
# devtools::install_github(&amp;#39;diegovalle/mxmaps&amp;#39;)
library(&amp;quot;mxmaps&amp;quot;)
plottable &amp;lt;- readRDS(here(&amp;quot;static&amp;quot;, &amp;quot;fires-mexico&amp;quot;, &amp;quot;fires_mexico.RDS&amp;quot;))
head(plottable)
##   Grados_Lon Minutos_Lon Segundos_Lon Grados_Lat Minutos_Lat Segundos_Lat
## 1        102           8         36.7         21          58         30.0
## 2        102          12         42.9         22          51         27.4
## 3        102          38         32.1         22           1         46.5
## 4        102          33         53.9         21          55         29.8
## 5        102          13          7.7         22           5         55.6
## 6        102          35         21.8         22          16         24.7
##              Tamaño  Año  Latitud  Longitud
## 1 11 a 20 Hectáreas 2010 21.97500 -102.8565
## 2 11 a 20 Hectáreas 2010 22.85761 -102.7881
## 3   0 a 5 Hectáreas 2010 22.02958 -102.3577
## 4   0 a 5 Hectáreas 2010 21.92494 -102.4350
## 5   0 a 5 Hectáreas 2010 22.09878 -102.7812
## 6   0 a 5 Hectáreas 2010 22.27353 -102.4106&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;plot&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Plot&lt;/h2&gt;
&lt;p&gt;My main objective was to remove the points moving above the country from year to year.
The problem is that the aesthetic was grouped ad the very definition by group.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;data(mxstate.map)

m &amp;lt;- ggplot() + 
  geom_polygon(data = mxstate.map, aes(x = long, y = lat, group = group), 
               fill = &amp;quot;grey&amp;quot;, color = &amp;quot;black&amp;quot;) +
  geom_point(data = plottable, 
             aes(x = Longitud, y = Latitud, group = Año), alpha = .2, color = &amp;quot;red&amp;quot;) +
  theme(plot.subtitle = element_text(size = 32, color = &amp;quot;grey&amp;quot;)) +
  scale_size_discrete()  +
  theme_map()  +
  coord_map()
## Warning: Using size for a discrete variable is not advised.
m&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://llrs.dev/post/2019/05/24/fires-mexico/index_files/figure-html/map-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;animation&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Animation&lt;/h2&gt;
&lt;p&gt;Now that we have the plot and the fires we can animate it by each year:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;gganimation &amp;lt;- m +
  transition_states(Año, transition_length = 11, state_length = 1, wrap = FALSE) +
    enter_fade() + 
    exit_fade() + 
    labs(title = &amp;quot;Incendios forestales registrados en México&amp;quot;,
         subtitle = &amp;quot;Año {closest_state}&amp;quot;, 
         x = element_blank(),
         y = element_blank(), 
         caption = &amp;quot;Source: CONAFOR / Elaboracion: @4drian.bautista &amp;amp; @Lluís_Rev&amp;quot;)

animate(gganimation, fps = 25, duration = 10)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://llrs.dev/post/2019/05/24/fires-mexico/index_files/figure-html/animation-1.gif&#34; /&gt;&lt;!-- --&gt;&lt;/p&gt;
&lt;/div&gt;
</description>
    </item>
    
  </channel>
</rss>
