Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following code has served me well. Customize it a little and you are done. <a href="http://files.eduardoleoni.com/map.png">alt text http://files.eduardoleoni.com/map.png</a></p> <pre><code>library(maptools) substitute your shapefiles here state.map &lt;- readShapeSpatial("BRASIL.shp") counties.map &lt;- readShapeSpatial("55mu2500gsd.shp") ## this is the variable we will be plotting counties.map@data$noise &lt;- rnorm(nrow(counties.map@data)) </code></pre> <p>heatmap function</p> <pre><code>plot.heat &lt;- function(counties.map,state.map,z,title=NULL,breaks=NULL,reverse=FALSE,cex.legend=1,bw=.2,col.vec=NULL,plot.legend=TRUE) { ##Break down the value variable if (is.null(breaks)) { breaks= seq( floor(min(counties.map@data[,z],na.rm=TRUE)*10)/10 , ceiling(max(counties.map@data[,z],na.rm=TRUE)*10)/10 ,.1) } counties.map@data$zCat &lt;- cut(counties.map@data[,z],breaks,include.lowest=TRUE) cutpoints &lt;- levels(counties.map@data$zCat) if (is.null(col.vec)) col.vec &lt;- heat.colors(length(levels(counties.map@data$zCat))) if (reverse) { cutpointsColors &lt;- rev(col.vec) } else { cutpointsColors &lt;- col.vec } levels(counties.map@data$zCat) &lt;- cutpointsColors plot(counties.map,border=gray(.8), lwd=bw,axes = FALSE, las = 1,col=as.character(counties.map@data$zCat)) if (!is.null(state.map)) { plot(state.map,add=TRUE,lwd=1) } ##with(counties.map.c,text(x,y,name,cex=0.75)) if (plot.legend) legend("bottomleft", cutpoints, fill = cutpointsColors,bty="n",title=title,cex=cex.legend) ##title("Cartogram") } </code></pre> <p>plot it</p> <pre><code>plot.heat(counties.map,state.map,z="noise",breaks=c(-Inf,-2,-1,0,1,2,Inf)) </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.
    3. 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