I have a problem with a 3d plot, suppose we have a matrix like this: v1 v2 v3 v4 jan-2010 0.5 0.25 0.25 0.3 feb-2010 0.35 0.12 0.12 0.4 mar-2010 0.15 0.25 0.25 0.1 and i want to plot this matrix in 3d plot where x-axis is the first column of the matrix above, y - axis is the first row of the matrix above and the z-axis is the numbers corresponding, so z(jan-2010,v3)=0.25 I was trying with persp() but i see that in this function z is a vector but in my case is a matrix, so i receive an error message I think this sound no so hard, but actually i couldn?t find a function doing this, is there actually such a function? Christian
On 05/07/2011 1:36 PM, ???????? wrote:> I have a problem with a 3d plot, suppose we have a matrix like this: > > v1 v2 v3 v4 > jan-2010 0.5 0.25 0.25 0.3 > feb-2010 0.35 0.12 0.12 0.4 > mar-2010 0.15 0.25 0.25 0.1 > > and i want to plot this matrix in 3d plot where x-axis is the first > column of the matrix above, y - axis is the first row of the matrix > above and the z-axis is the numbers corresponding, so > z(jan-2010,v3)=0.25 > > I was trying with persp() but i see that in this function z is a > vector but in my case is a matrix, so i receive an error message > I think this sound no so hard, but actually i couldn?t find a function > doing this, is there actually such a function?persp() handles exactly the case you describe, but it wants numeric x and y. You didn't show what you tried, but this works: x <- 1:3 y <- 1:4 z <- matrix(rnorm(12), nrow=3) persp(x,y,z, col="red") It's not a very useful plot with the random data; it might be better with yours. Duncan Murdoch
On Jul 5, 2011, at 1:36 PM, ???????? wrote:> I have a problem with a 3d plot, suppose we have a matrix like this: > > v1 v2 v3 v4 > jan-2010 0.5 0.25 0.25 0.3 > feb-2010 0.35 0.12 0.12 0.4 > mar-2010 0.15 0.25 0.25 0.1 > > and i want to plot this matrix in 3d plot where x-axis is the first > column of the matrix above, y - axis is the first row of the matrix > above and the z-axis is the numbers corresponding, so > z(jan-2010,v3)=0.25 > > I was trying with persp()But you didn't show your code.> but i see that in this function z is a > vectorThat is not how I read help(persp).> but in my case is a matrix,Assuming the matrix is named "z", what happens with : persp(z=z)> so i receive an error messageAnd after reading the Posting Guide you will see that you are asked to report any error message verbatim. And perhaps even more importantly it asks that you provide a reproducible version of your object with dump. It's even easier to use dput, but do include one or the other.> I think this sound no so hard, but actually i couldn?t find a > function > doing this, is there actually such a function?There are many. But why not see if you can get persp to work?> Christian > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT