Ok now I've read in my dataframe. The file is set up like this:
x y z
1 1 1
1 2 2
1 3 5
2 1 3
2 2 9
2 3 2
3 1 8
3 2 4
3 3 7
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.
I have been fooling around with image. The examples show something like
x<-seq(0,1)
y<-x
func<-function(x,y) {x/(x+y)}
z<-outer(x,y,"func")
image(z)
or
image(x,y,z)
The bit with outer is required to make z a matrix.
I tried this idea:
x<-seq(1,4)
y<-x
z<-seq(1,16)
func<-function(x,y) {z}
z<-outer(x,y,"func")
# z
# [,1] [,2] [,3] [,4]
#[1,] 1 5 9 13
#[2,] 2 6 10 14
#[3,] 3 7 11 15
#[4,] 4 8 12 16
image(x,y,z,col=gray(16:1/16))
I still have the problem that in reality my x and y vectors are not in
ascending order as required by image.
Anyway, can someone please explain how to get my data into a form
acceptable to image? Thanks very much!
Bill Simpson
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 length(z)=length(x)*length(y) 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 generated. 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 image(unique(x),unique(y),z) If you have full-length x and y vectors that are not in the right order you can use o<-order(y,x) image(unique(x[o]),unique(y[o]),z[o]) which should probably be built in to image(). Thomas Lumley ------------------------ Biostatistics 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._