[R] How to visualise spatial raster data?

Roger Bivand Roger.Bivand at nhh.no
Fri Jan 6 19:41:03 CET 2006

On Fri, 6 Jan 2006, Jan Verbesselt wrote:

> Dear R help,
> We are trying to visualise spatial raster data. We have per line, X & Y
> coordinates and Z(data). How could we visualise this type of data? We
> also would like to add extra data points to this plot based on new X,Y
> and Z data.
> We used the following function but would like to use only the  graph in
> the upper right corner (spatial one) . Similar to the graph cfr.
> http://www.est.ufpr.br/geoR/geoRdoc/vignette/geoRintro/geoRintrose3.html#x4-60003.1
> geo_iRVI <- as.geodata(pixels_blok,coords.col=2:3, data.col=4)
> plot(geo_iRVI)
> How can this plot be optimized? And can we add other points to it?
>  Another solution could be:
> filled.contour(AVG,color=terrain.colors, xlab="Longitude (°)",
> ylab="Latitude (°)) but therefore the data needs to be organised
> differently, not per line of X,Y coordinates but in a raster form.
> Can anyone advise functions to visualise spatial raster data optimally?

The SpatialGrid and SpatialPixels classes in the sp package provide a 
starting point:

xygrid <- expand.grid(1:25, 1:25)
xysubset <- xygrid[1:400,]
xysp <- SpatialPixels(SpatialPoints(xysubset))
xyz <- SpatialPixelsDataFrame(xysp, data=data.frame(z=runif(400)))
image(xyz, xlim=c(0,26), ylim=c(0,26))
xyadd <- xygrid[501:625,]
xyspadd <- SpatialPixels(SpatialPoints(xyadd))
xyzadd <- SpatialPixelsDataFrame(xyspadd, data=data.frame(z=runif(125)))
image(xyzadd, add=TRUE)

SpatialPixels need to be regularly spaced, but do not have to be a full 
rectangular grid, and have an image() method.

You may find the R-sig-geo mailing list more appropriate for this kind of 
question, access via the "Spatial" Task View on CRAN.

> thanks,
> Jan
> windows R 2.2
> library(geoR) 
> library(akima) 

Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no

More information about the R-help mailing list