Skip to content
Prev 69778 / 398525 Next

Fitting Contour to Data Points

Laura Quinn wrote:
You are misunderstanding what the x, y and z arguments want. From 
?contour we have

      x,y: locations of grid lines at which the values in 'z' are
           measured.  These must be in ascending order.  By default,
           equally spaced values from 0 to 1 are used.  If 'x' is a
           'list', its components 'x$x' and 'x$y' are used for 'x' and
           'y', respectively. If the list has component 'z' this is used
           for 'z'.

        z: a matrix containing the values to be plotted ('NA's are
           allowed).  Note that 'x' can be used instead of 'z' for
           convenience.

So if you have a 10 x 10 grid, you will have 10 values each for x and y 
and a 10x10 matrix of the 100 points as z. But you don't have a regular 
grid so you can't use contour directly. Without knowing your data, 
you'll have to get values on to a regular grid using something like 
package akima and it's function interp(), then contour the interpolated 
surface.

There are likely to be other ways. MASS (the book) has an example of 
using loess() to predict surfaces from irregular data for example...

HTH

Gav