title: animated gadm map in R
body: <p>everybody, sorry for disturb, but I am being quite new with r faced a crucial difficuty: I want to create an animated map of Russin with changes in unemployment with differnt years, like. To start with I read a number of themes here, including <a href="https://stackoverflow.com/questions/1298100/creating-a-movie-from-a-series-of-plots-in-r">Creating a Movie from a Series of Plots in R</a>, although I am stil couldn't do it rightly. What I want to have as a  result is animated map like <a href="https://i.stack.imgur.com/fUL6w.gif" rel="nofollow noreferrer">here</a> , but with unemployment, like I have made for one year!<img src="https://i.stack.imgur.com/50AJd.png" alt="enter image description here">
  Here is the code :</p>
  
  <pre><code>require(sp)
  require(maptools)
  require(RColorBrewer)
  require(rgdal)
   rus&lt;-url("http://www.filefactory.com/file/4h1hb5c1cw7r/n/RUS_adm1_RData")
  print(load(rus))
  
  
  
  
  
    unempl1 &lt;- read.delim2(file="C:\\unempl11.txt", header = TRUE, 
          sep = ";",quote = "", dec=",", stringsAsFactors=F)
  unempl2&lt;- read.delim2(file="C:\\unempl12.txt", header = TRUE, 
          sep = ";",quote = "", dec=",", stringsAsFactors=F)
  
  gadm_names &lt;-gadm.prj$NAME_1
  
  
  total &lt;- length(gadm_names)
  pb &lt;- txtProgressBar(min = 0, max = total, style = 3) 
  
  order &lt;- vector()
  
  for (i in 1:total){  
  
    order[i] &lt;- agrep(gadm_names[i], unempl1$region, 
                       max.distance = 0.2)[1]
   setTxtProgressBar(pb, i)               # update progress bar
  }
  
  
  for (l in 1:total){  
  
    order[l] &lt;- agrep(gadm_names[l], unempl2$region, 
                       max.distance = 0.2)[1]
   setTxtProgressBar(pb, i)               # update progress bar
  }
  
  col_no_1 &lt;- as.factor(as.numeric(cut(unempl1$data[order],
                      c(0,2.5,5,7.5,10,15,100))))
  
  col_no_2&lt;- as.factor(as.numeric(cut(unempl2$data[order],
                      c(0,2.5,5,7.5,10,15,100))))
  
  
  levels(col_no_1) &lt;- c("&lt;2,5%", "2,5-5%", "5-7,5%",
                      "7,5-10%", "10-15%", "&gt;15%")
  
  
  gadm.prj$col_no_1 &lt;- col_no_1
  
  myPalette1&lt;-brewer.pal(6,"Purples")
  
  
  levels(col_no_2) &lt;- c("&lt;2,5%", "2,5-5%", "5-7,5%",
                      "7,5-10%", "10-15%", "&gt;15%")
  
  
  gadm.prj$col_no_2 &lt;- col_no_2
  
  myPalette2&lt;-brewer.pal(6,"Purples")
  
  
  
  
  proj4.str &lt;- CRS("+init=epsg:3413 +lon_0=105")
  gadm.prj &lt;- spTransform(gadm, proj4.str)
  
  spplot(gadm.prj, "col_no", col=grey(.9), col.regions=myPalette,
  main="Unemployment in Russia by region")
  </code></pre>
  
  <p>Sorry for being such not understanding, but I really need a help.
  Thanks in advance!</p>
  
  <p><a href="http://www.filefactory.com/file/complete.php/5oy5c0n9bomh/" rel="nofollow noreferrer">Here is data to be able to reproduce the code</a></p>
  
  <p>New code, which I tried using following advice</p>
  
  <pre><code>library(sp)
  library(rgdal)
  library(spacetime)
  library(animation)
  rus &lt;- url("http://www.filefactory.com/file/4h1hb5c1cw7r/n/RUS_adm1_RData")
  load(rus)
  proj4.str &lt;- CRS("+init=epsg:3413 +lon_0=105")
  gadm.prj &lt;- spTransform(gadm, proj4.str)
  N &lt;- nrow(gadm.prj)
  pols &lt;- geometry(gadm.prj)
  nms&lt;-gadm$NAME_1
  vals1  &lt;- read.csv2("C:\\unempl11.txt")
  ord1 &lt;- match(nms, vals1$region)
  vals1 &lt;- vals1[ord1,]
  
  vals2 &lt;- read.csv2("C:\\unempl12.txt")
  ord2 &lt;- match(nms, vals2$region)
  vals2 &lt;- vals2[ord2,]
  
  nDays &lt;- 2
  tt &lt;- seq(as.Date('2011-01-01'), by='year', length=nDays)
  vals &lt;- data.frame(rbind(vals1, vals2))
  
  gadmST &lt;- STFDF(pols, time=tt, data=vals)
  
  
  
  stplot(gadmST, animate=1, do.repeat=FALSE)
  </code></pre>
  
  <p><a href="http://www.filefactory.com/file/4wg0wp0350a9/n/unempldata_rar" rel="nofollow noreferrer">New corrected data</a></p>