Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>spacetime</code> package defines the <code>stplot</code> method with several graphical alternatives. Use its <code>animate</code> argument to build an animation. First you have to define a <code>STFDF</code> object (read the package documentation and <a href="http://www.jstatsoft.org/v51/i07/" rel="nofollow">this paper</a> for details)</p> <p>First import your <code>SpatialPolygonsDataFrame</code>...:</p> <pre><code>library(sp) library(rgdal) library(spacetime) 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) </code></pre> <p>... and then add your data (two days). You have to reorder the <code>data.frame</code> with the codes of the <code>SpatialPolygon</code>. </p> <pre><code>vals1 &lt;- read.csv2('/tmp/unempldata/unempl11.txt') ord1 &lt;- match(nms, vals1$region) vals1 &lt;- vals1[ord1,] vals2 &lt;- read.csv2('/tmp/unempldata/unempl12.txt') ord2 &lt;- match(nms, vals2$region) vals2 &lt;- vals2[ord2,] </code></pre> <p>Unfortunately, the region names of your data does not match exactly with the region names of the polygons. Therefore, the previous code will provide <code>data.frame</code> with less rows than polygons, and the next code will fail. You may want to clean your data before using this code (read the <code>STFDF</code> help page to understand how to define <code>gadmST</code>):</p> <pre><code>nDays &lt;- 2 tt &lt;- seq(as.Date('2013-01-01'), by='day', length=nDays) vals &lt;- data.frame(unempl=rbind(vals1, vals2)[,-1]) gadmST &lt;- STFDF(pols, time=tt, data=vals) </code></pre> <p>Now you are ready for the animation. Read the <code>stplot</code> help page to improve the graphical output using its arguments:</p> <pre><code>png('gadm%02d.png') stplot(gadmST, animate=1, do.repeat=FALSE) dev.off() </code></pre> <p>The <code>png</code> files are the frames of a movie that can be produced with <code>ffmpeg</code>.</p> <pre><code>system('ffmpeg -r 1 -i gadm%02d.png gadm.mp4') </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload