[R-sig-Geo] About plotting maximum data over a region.-

Ashton Shortridge ashton at msu.edu
Tue Aug 31 21:13:14 CEST 2010

On 2010-08-31, Freddy López, wrote:
> Dear ALL,
> Perhaps my problem does not belong exactly to this list... I apologize for
> this.
> My situation is the following:
> I have a dataset with 26 sites (columns) whose values are annual
> maximum since 1960 up to 1999 (40 rows) and I want to plotting it.  Of
> course I have also the coordinates from each site.
> I have seen one example similar to what I am looking for (function
> simmaxstab() in SpatialExtremes):
> >filled.contour(x, y, log(data[,,1]), color.palette = terrain.colors)
> But at first glance it does not work to my data. The error that it report is:
> > filled.contour(coor2[,1], coor2[,2], nueva2)
> Error en filled.contour(coor2[, 1], coor2[, 2], nueva2) :
>   increasing 'x' and 'y' values expected
> Can anybody help me to plot my particular dataset?
> Thanks in advance.

Hi Freddy,

Your problem is that filled.contour assumes a matrix input - essentially a 
whole field of z-values. I suspect what you have are scattered locations with 
z-values for each one. You have two options:

1. Interpolate your scattered points to a grid, and plot that, maybe with 
filled.contour. Interpolation methods are very numerous in R and beyond the 
scope of this answer, but maybe idw() in the gstat package would be a place to 

2. Plot the point locations directly, and color them according to their z-
value. Maybe something like this would work:
par(pty="s")  # square plotting region
plot(coor2[,1], coor2[,2], main="Locations")  # Just the locations
plot(coor2[,1], coor2[,2], main="Nueva2 at my Locations", 
     col=rainbow(n=10, start=0.50, end=0.65)[cut(nueva2,10)], pch=19)
points(coor2[,1], coor2[,2], pch=1, cex=1.1)  # draws a black outline

Hope this helps,


Ashton Shortridge
Associate Professor			ashton at msu.edu
Dept of Geography			http://www.msu.edu/~ashton
235 Geography Building		ph (517) 432-3561
Michigan State University		fx (517) 432-1671

More information about the R-sig-Geo mailing list