I think my problems are coused by a fundamental R incompatibility in how
matrices are stored and the usual way of specifying Cartesian coordinates.
When I do
data<-read.table("~/r/rt/data/unif/6cbcif2d.out",header=TRUE)
x<-unique(data$lag1)
y<-unique(data$lag2)
z<-matrix(data$cif2d,length(y),length(x))
This z matrix is printed apparently correctly from a Cartesian point of
view
z
[,1] [,2] [,3]
[1,] 11 21 31
[2,] 12 22 32
[3,] 13 23 33
But if you look at the numbers on the top and side you see that the row
and column indexes have been reversed! By that I mean in Cartesian system
you do (x,y) which is equiv to (col,row); matrix() prints the numbers
above in accord with (col,row) but they are actually stored as (row,col).
z[2,1]
[1] 12
whereas I would expect 21.
If this is standard for you stats people that is too bad, in my opinion.
I always think in terms of x,y,z = col, row, height.
So I need to use:
z<-matrix(data$cif2d,length(y),length(x), byrow=TRUE)
How do you avoid getting mixed up when making an image plot of a matrix?
I like the way persp() is set up, which is NOT the way image() is set up.
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I think my problems are coused by a fundamental R incompatibility in how
matrices are stored and the usual way of specifying Cartesian coordinates.
<snip>
But if you look at the numbers on the top and side you see that the row
and column indexes have been reversed! By that I mean in Cartesian system
you do (x,y) which is equiv to (col,row); matrix() prints the numbers
above in accord with (col,row) but they are actually stored as (row,col).
z[2,1]
[1] 12
whereas I would expect 21.
If this is standard for you stats people that is too bad, in my opinion.
I always think in terms of x,y,z = col, row, height.
It is somewhat standard. It probably comes from having to work with only
two-dimensional data structures, which makes it logical to have one
dimension indexing records and the other indexing variables. Spatial data
would then be stored with columns x,y,d1,d2,d3 for multiple data fields
d1-d3.
For data observed on a rectangular grid it might well be better to use a
3-d array with d1-d3 on slices of the array. But even for spatial data if
they are observed on some other grid (like the triangular equal area grids
used for some global-scale satellite data) or at irregular points it
doesn't help at all.
There may, on the other hand, be a good case for having image() work the
other way, though you could just do image(x,y,t(z)) to transpose the z
matrix.
Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
There may, on the other hand, be a good case for having image() work the
other way, though you could just do image(x,y,t(z)) to transpose the z
matrix.
Yes thanks, this works fine. It is just confusing to me.
Bill
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._