Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are trying to display points but you are using an <code>SpatialPolygonsDataFrame</code> source. You can extract the coordinates of the centroids with <code>coordinates</code> and use them as coordinates of your data, but I am not sure if that is what you need:</p> <pre><code>library(sp) library(rgdal) 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) ## IDs needed to match polygons and data nms &lt;- gadm.prj$NAME_1 ll &lt;- coordinates(gadm.prj) </code></pre> <p>On the other hand, I cannot retrieve correctly the <code>data</code> column of your file. I fill it with some noise:</p> <pre><code>popul &lt;- read.csv2('/tmp/popul.txt') popul$data &lt;- runif(nrow(popul)) </code></pre> <p>Now it's time to match coordinates and data (similar to what we did in <a href="https://stackoverflow.com/questions/17163670/animated-gadm-map-in-r/17180169#17180169">this previous question</a>):</p> <pre><code>ord1 &lt;- match(nms, popul$region) popul &lt;- popul[ord1,] row.names(popul) &lt;- nms row.names(ll) &lt;- nms popSP &lt;- SpatialPointsDataFrame(ll, popul["data"], proj4string=proj4.str) </code></pre> <p>This <code>SpatialPointsDataFrame</code> can be directly displayed with <code>spplot</code> with the boundaries below using <code>sp.layout</code>.</p> <pre><code>spplot(popSP, sp.layout=list('sp.polygons', gadm.prj)) </code></pre> <p><img src="https://i.stack.imgur.com/GExCG.png" alt="result"></p>
 

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