Oliver
2011-Jun-08 14:57 UTC
[R] 3D-plotting a 2D-matrix that contains z-values (3rd dimension)
Hello, say I have a 2D-matrix (indexed by x and y), which contains z values, which I want to plot over x-y. Either dotted, or if possible as a landscape. I tried around with persp and plot3d (from rgl) and persp3d (from rgl). I sometimes get something that looks good and a while later, when trying some new data I need to worry about that again. Is there something lika a convenience function that can be used to feed the data into persp, rgl::plot3d and rgl::persp3d? At least persp3d is picky about the order of the input data, and I somehow always start again. (plot3d seems to be most mathcing how I think). Isn't that a very common case, where my z_x_y = mydata[x,y] ? Maybe I just don't know the right function that helps me. Any idea about that? Ciao, Oliver
Uwe Ligges
2011-Jun-09 09:22 UTC
[R] 3D-plotting a 2D-matrix that contains z-values (3rd dimension)
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. If you need to calculate z values from x and y using some function foo, outer(x, y, foo) is typically your friend. Uwe Ligges On 08.06.2011 16:57, Oliver wrote:> Hello, > > say I have a 2D-matrix (indexed by x and y), which contains > z values, which I want to plot over x-y. > > Either dotted, or if possible as a landscape. > > I tried around with persp and plot3d (from rgl) > and persp3d (from rgl). > > I sometimes get something that looks good and a while later, when > trying some new data I need to worry about that again. > > Is there something lika a convenience function that > can be used to feed the data into persp, rgl::plot3d and rgl::persp3d? > > At least persp3d is picky about the order of the input data, > and I somehow always start again. > > (plot3d seems to be most mathcing how I think). > > Isn't that a very common case, where my z_x_y = mydata[x,y] ? > > Maybe I just don't know the right function that helps me. > > Any idea about that? > > > Ciao, > Oliver > > ______________________________________________ > 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.