Re: R-beta: image(x,y,z)?

Thomas Lumley (
Tue, 28 Apr 1998 08:59:01 -0700 (PDT)

Date: Tue, 28 Apr 1998 08:59:01 -0700 (PDT)
From: Thomas Lumley <>
To: Bill Simpson <>
Subject: Re: R-beta: image(x,y,z)?
In-Reply-To: <>

On Tue, 28 Apr 1998, Bill Simpson wrote:

> I can get at data$x, data$y, data$z. I want to do an image plot.  Ideally
> image (or a relative of image) would accept the vectors data$x, data$y,
> data$z as arguments. (After all, if you can do plot(x,y) on vectors x and
> y, why can't you do image(x,y,z) on vectors x, y, and z?) However it
> doesn't work like that.

The real reason is that it isn't written that way.  There is a good
rationalisation, though.  image() is a surface plot, not a 3-d
scatterplot, and so it is necessary that z is defined at every point on
the x,y grid (otherwise we don't know what color to plot). This is hard to
ensure when you have image(x,y,z) for vectors

> Anyway, can someone please explain how to get my data into a form
> acceptable to image?  Thanks very much!

In fact, you don't need z to be a matrix.  What you need is 
x increasing
y increasing

The idea is that values of z are ordered in the same way as if it were
generated by outer(x,y,somefunction), which will generally be how it was

We probably shouldn't require x and y to be increasing -- we could still
assume z is ordered as if it were outer(x,y,somefunction).

Anyway, one thing you can do if you have the full x and y vectors is


If you have full-length x and y vectors that are not in the right order
you can use 


which should probably be built in to image().

Thomas Lumley
Uni of Washington	
Box 357232		
Seattle WA 98195-7232	

r-help mailing list -- Read
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: