2

Say I have 3 variables such that

x=1:9
y=c(1,1,1,2,2,2,3,3,3)
z=6:14

How can I rearrange the data so that I can make a contour plot of the data with r? I am getting the message

Error in contour.default(x, y, z) : 
  increasing 'x' and 'y' values expected

Thank you.

Francisco Alvarado
  • 2,815
  • 2
  • 26
  • 51
SnowFrog
  • 1,162
  • 4
  • 19
  • 38
  • I made z an array but I still wasn't succesful despite following Tyler's instructions. In the end I used contourplot() from the lattice library much easier to understand. See [Ajay Shah's explanation here](https://stat.ethz.ch/pipermail/r-help/2006-July/108499.html "this") for details. – SnowFrog May 02 '11 at 15:13

1 Answers1

1

z is a matrix of values where contour lines are to be drawn. x and y are their respective location. "Tyler" at r-help mailing list explains this and gives an example of how to transform your data to make things work. See also examples in the help of ?contour.

x = seq(0, 10, by = 0.5)
y = seq(0, 10, by = 0.5)
z <- outer(x, y)

contour(x, y, z)
Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197