[R] Surprise when mapping matrix to image
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Aug 26 22:43:50 CEST 2004
On Thu, 26 Aug 2004, Glynn, Earl wrote:
> Start with:
>
> > x <- c(1:7,1)
> > dim(x) <- c(2,4)
> > x
> [,1] [,2] [,3] [,4]
> [1,] 1 3 5 7
> [2,] 2 4 6 1
>
> 2 Rows of 4 Columns. Upper-left and lower-right elements of the matrix
> are the same.
>
> All to this point makes good sense.
It's pure convention: see below.
> > image(x)
>
> However, this image shows 2 columns of 4 rows. The lower-left and
> upper-right elements are the same. This does not make sense to me.
> Did I miss some simple parameter to "fix" all of this naturally? Why
> would the numeric matrix of "x" and the image of "x" have such a
> different geometry?
Did you try reading the help for image? You don't seem to understand it
if you actually did. It seems you are looking for
image(t(x)[ncol(x):1, ])
Easy!
Mathematical conventions are just that, conventions. They differ by field
of mathematics. Don't ask us why matrix rows are numbered down but graphs
are numbered up the y axis, nor why x comes before y but row before
column. But the matrix layout has always seemed illogical to me.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list