[R] upside down image/data
Jenny Barnes
jmb at mssl.ucl.ac.uk
Wed Dec 13 15:06:00 CET 2006
Thomas,
Thank you for this example, makes it easier to see what levelplot does - does
this mean that EVERY time I want to plot with levelplot() I have to not only
reverse the columns [,ncol(output.temp):1] but also have to transform the matrix
as below? I am only suprised as I don't remember having read about this in the
R-info in ?levelplot or R-help website and it seems like a fundamental thing to
know if using levelplot!
Thanks,
Jenny
>
> 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
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jennifer Barnes
PhD student - long range drought prediction
Climate Extremes
Department of Space and Climate Physics
University College London
Holmbury St Mary, Dorking
Surrey
RH5 6NT
01483 204149
07916 139187
Web: http://climate.mssl.ucl.ac.uk
More information about the R-help
mailing list