[R] Contour - data points not in ascending order?
(Ted Harding)
Ted.Harding at manchester.ac.uk
Tue Jun 29 11:36:22 CEST 2010
On 29-Jun-10 08:53:48, Kirkeby wrote:
> Hi again.
>
> I have made an example of my data:
>
> x<-c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4)
> y<-c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4)
> z <- c(12,23,23,42,12,1,1,32,5,45,65,76,32,21,23,43)
> data <- unique(cbind(x,y,z))
> contour(x,y,z, col="red", xlim=c(0,1), ylim=c(0,1), labcex=0.7,
> cex="12")
>
> -which gives an error message.
>
> /CK
Have a close look at ?contour
x,y: locations of grid lines at which the values in 'z'
are measured. These must be in ascending order.
z: a matrix containing the values to be plotted
('NA's are allowed).
Notice that 'contour' interprets the 'z' matrix as a table
of 'f(x[i], y[j])' values, so that the x axis corresponds
to row number and the y axis to column number, with
column 1 at the bottom, i.e. a 90 degree clockwise
rotation of the conventional textual layout.
So your data above:
x<-c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4)
y<-c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4)
z <- c(12,23,23,42,12,1,1,32,5,45,65,76,32,21,23,43)
correspond to:
x <- c(1,2,3,4) ; y <- c(1,2,3,4)
(i.e. locations of grid *lines*, not points)
with z being the matrix
12 12 5 32
23 1 45 21
23 1 65 23
42 32 76 43
i.e.
z <- matrix(c(12,23,23,42,12,1,1,32,5,45,65,76,32,21,23,43),ncol=4)
Then
contour(x,y,z)
should do the job!
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 29-Jun-10 Time: 10:36:20
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list