[R] question on image() function?

Duncan Murdoch murdoch at stats.uwo.ca
Thu Nov 8 19:13:18 CET 2007


On 11/8/2007 11:51 AM, zhijie zhang wrote:
> Dear friends,
>   My dataset is like the following:
>          x                y              mcpvalue
> 0.4603578     0.6247629       1.001
> 0.4603715     0.6247788        1.001
> 0.4603852     0.6247948       1.001
> 0.4110561     0.5664841       0.995
>  The x and y variables are unsorted.
>  I use the function image(x,y,mcpvalue) to generate a plot, but the error
> is that "increasing 'x' and 'y' values are expected". So i use
>    image(x=seq(min(x),max(x)), y=seq(min(y),max(y)),z=as.matrix
> (result$mcpvalue))
> to do it again, but there is still an error "dimensions of z are not
> length(x)(-1) times length(y)(-1)".
>   Anybody can show me how to use the image() correctly with the original x/y
> unsorted?

You can't, it doesn't know how to handle that kind of data.

image() is designed to display a matrix of values.  The x and y values 
tell it where to put the rows and columns of the matrix.

You have a set of points.  You need to fit a surface to them, evaluate 
the surface on a grid, and pass that to image().

There are many ways to do that; the akima package has the interp() 
function for instance.

Duncan Murdoch



More information about the R-help mailing list