[R] upside down image/data

Thomas Harte thomas.harte at yahoo.com
Wed Dec 13 14:52:55 CET 2006


	rm(list=ls(all=TRUE))
	graphics.off()
	# make a test matrix:
	nr<- 3
	nc<- 4
	# the data:
	( m<- matrix((1:(nr*nc)), nr, nc) )
	     [,1] [,2] [,3] [,4]
	[1,]    1    4    7   10
	[2,]    2    5    8   11
	[3,]    3    6    9   12

	# the way that levelplot (and image) displays the data:
	t(m)[dim(t(m))[1]:1, ]
	     [,1] [,2] [,3]
	[1,]   10   11   12
	[2,]    7    8    9
	[3,]    4    5    6
	[4,]    1    2    3

	# undo what levelplot does by performing the inverse transformation
	inverse<- function(x) t(x[dim(x)[1]:1, ]) 

	windows(); levelplot(m, main="levelplot(m)")
	windows(); levelplot(inverse(m), main="levelplot(inverse(m))")

	> Message: 7
	> Date: Mon, 11 Dec 2006 12:28:17 +0000 (GMT)
	> From: Jenny Barnes <jmb at mssl.ucl.ac.uk>
	> Subject: [R] upside down image/data
	> To: r-help at stat.math.ethz.ch
	> Message-ID: <200612111228.kBBCSHrj013960 at msslhb.mssl.ucl.ac.uk>
	> Content-Type: TEXT/plain; charset=us-ascii
	> 
	> Dear R-community,
	> 
	> I am looking for some simple advice - I have a matrix (therefore 2 dimensional) 
	> of global temperature. 
	> 
	> Having read R-help I think that when I ask R to image() or levelplot() my matrix 
	> will it actually appear upside down - I think I therefore need to use the line:
	> > levelplot(temperature.matrix[,ncol(output.temp):1], ........)
	> to get it looking like it was on the globe due to the matrix rows increasing in 
	> number down the matrix in its dimensions on longitude and latitude but the 
	> y-axis coordinates increase up the axis.
	> 
	> Can anyone simply tell me whether this is correct as I find it very hard to know 
	> which way up my data should be and I cannot tell which is correct simply by 
	> looking at it!
	> 
	> Many thanks for your time in reading this problem,
	> 
	> Jenny Barnes



More information about the R-help mailing list