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

Thomas Lumley thomas at biostat.washington.edu
Tue Apr 28 17:59:01 CEST 1998

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 http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list