[R] 3D-plotting a 2D-matrix that contains z-values (3rd dimension)

oliver oliver at first.in-berlin.de
Thu Jun 9 13:59:52 CEST 2011


On Thu, Jun 09, 2011 at 01:50:17PM +0200, Uwe Ligges wrote:
> 
> 
> On 09.06.2011 13:37, oliver wrote:
> >On Thu, Jun 09, 2011 at 11:22:54AM +0200, Uwe Ligges wrote:
> >>Well,
> >>
> >>persp(x, y, z) does exactly what you asked for: it plots tha matrix
> >>z along the values given by the vectors x and y.
> >
> >But I don't have these vectors x and y, so I have to
> >create them just to call persp().
> >And persp also needs the values only to rise.
> >
> >But if I have x and y, and I want to have only rising numbers for x and y,m
> >I need somehow to create those values, and expand.grid()
> >would not create value combinations that are only rising.
> >(Or did I miss an option for expand.grid, which does that?)
> >
> >>If you need to calculate z values from x and y using some function
> >>foo, outer(x, y, foo) is typically your friend.
> >
> >OK.
> >
> >And what, if I want to generate the mathcing x- and y- values
> >for a matrix, that has x- and y implicitly, but I only have the
> >z-values inside the matrix?
> >
> >So, my problem is the other way around.
> >I don't want to calc the z for my x-and y, I want to generate the x-
> >and y- values for my matrix of z-values.
> 
> 
> Actually you just need to pass the matrix Z if the scale of the axes
> is irrelevant:
> 
> persp(Z)
[...]

nice. Thank you!

(this also works with rgl::persp3d() which I like even more)

You made my day! :)

Ciao,
   Oliver



More information about the R-help mailing list