Developing Geographic Thematic Maps with R


There are clearly a number of packages in R for all sorts of spatial analysis. That can by seen in the CRAN Task View: Analysis of Spatial Data. These packages are numerous and diverse, but all I want to do is some simple thematic maps. I have data with county and state FIPS codes and I have ESRI shape files of county and state boundaries and the accompanying FIPS codes which allows joining with the data. The shape files could be easily converted to other formats, if needed.

So what's the most straight forward way to create thematic maps with R?

This map looks like it was created with an ESRI Arc product, but this is the type of thing I would like to do with R:

alt text Map copied from here.

8/11/2009 3:16:31 PM

Accepted Answer

The following code has served me well. Customize it a little and you are done. alt text

substitute your shapefiles here <- readShapeSpatial("BRASIL.shp") <- readShapeSpatial("55mu2500gsd.shp")
## this is the variable we will be plotting$noise <- rnorm(nrow(

heatmap function

plot.heat <- function(,,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)) {
  }$zCat <- cut([,z],breaks,include.lowest=TRUE)
  cutpoints <- levels($zCat)
  if (is.null(col.vec)) col.vec <- heat.colors(length(levels($zCat)))
  if (reverse) {
    cutpointsColors <- rev(col.vec)
  } else {
    cutpointsColors <- col.vec
  levels($zCat) <- cutpointsColors
  plot(,border=gray(.8), lwd=bw,axes = FALSE, las = 1,col=as.character($zCat))
  if (!is.null( {
  if (plot.legend) legend("bottomleft", cutpoints, fill = cutpointsColors,bty="n",title=title,cex=cex.legend)

plot it

4/13/2019 7:48:37 AM

Thought I would add some new information here since there has been some activity around this topic since the posting. Here are two great links to "Choropleth Map R Challenge" on the Revolutions blog:

Choropleth Map R Challenge

Choropleth Challenge Results

Hopefully these are useful for people viewing this question.

All the best,


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow