next up previous
Next: Working with shape files Up: Spatial and spatio-temporal data Previous: Spatial and spatio-temporal data


Image plots for displaying spatial observations

One nice way to display observations that are indexed spatially is small circles of differing color, where the two axes represent two-dimensional space. I've created a 'point map' function, 'pmap', to do this:

pmap<- 
  function(y,x,xlab='',ylab='',col=tim.colors(32),zlim=NULL,shrink=.9,cex=.7,pch=19,...){ 
     if(is.null(zlim)){  
     zlim=range(y,na.rm=T)+c(-1e-15,1e-15)  
  }  
  out=as.numeric(cut(y,breaks=seq(zlim[1],zlim[2],length=length(col)+1)))  
  if(shrink<1){  
      tmp=par()$plt  
      tmp[2]=shrink*tmp[2]  
      par(plt=tmp)  
  }  
  plot(x[,1],x[,2],col=col[out],xlab=xlab,ylab=ylab,pch=pch,cex=cex,...)  
  if(shrink<1){ image.plot(y,x=x,add=T,legend.only=T,zlim=zlim,col=col)  
  } 
}

Note that this requires the fields library, which supplies Tim Hoar's nice color scheme, tim.colors(), but you could use another color scheme of your choice. If you use shrink=1, then no legend will be created. You can control the symbol that gets plotted at each location using the pch argument and the size of the symbol using the cex argument.

Keywords: image.plot, R, plot, observations, spatial

Last modified 12/20/09.



Chris Paciorek 2012-01-21