hi, all I am looking at R package RGL to draw a colored mesh/surface plot like this one (from matlab). http://www.mathworks.com/access/helpdesk/help/techdoc/visualize/cbar.gif The key features I am looking for is surfaced with grid and color, but not the terrain-like gradient. but I didn't come even close to it after browsing through rgl help file. have anyone drawn something like this before, is this doable afterall? thanks Oliver
can I draw 3D plot like this using R?
6 messages · Stephen J. Barr, Rob Denniker, Duncan Murdoch +1 more
Yes, you can: For example: http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=40 In general RGraphGallery is quite useful for getting ideas and source code to different kinds of graphs and plots. Regards, -stephen
========================================== Stephen J. Barr University of Washington Dept. of Applied and Computational Math Sciences Dept. of Economics WEB: www.econsteve.com ========================================== On Wed, Mar 11, 2009 at 8:35 PM, Oliver <fwang2 at gmail.com> wrote: > hi, all > > I am looking at R package RGL to draw a colored mesh/surface plot like > this one (from matlab). > http://www.mathworks.com/access/helpdesk/help/techdoc/visualize/cbar.gif > > The key features I am looking for is surfaced with grid and color, but > not the terrain-like gradient. ?but I didn't come even close to it > after browsing through rgl help file. > > have anyone drawn something like this before, is this doable afterall? > > thanks > > 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. >
Sure, you can do that. Check out wireframe() in the lattice library.
-----Original Message----- From: fwang2 at gmail.com Sent: Wed, 11 Mar 2009 20:35:22 -0700 (PDT) To: r-help at r-project.org Subject: [R] can I draw 3D plot like this using R? hi, all I am looking at R package RGL to draw a colored mesh/surface plot like this one (from matlab). http://www.mathworks.com/access/helpdesk/help/techdoc/visualize/cbar.gif The key features I am looking for is surfaced with grid and color, but not the terrain-like gradient. but I didn't come even close to it after browsing through rgl help file. have anyone drawn something like this before, is this doable afterall? thanks 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.
On 11/03/2009 11:35 PM, Oliver wrote:
hi, all I am looking at R package RGL to draw a colored mesh/surface plot like this one (from matlab). http://www.mathworks.com/access/helpdesk/help/techdoc/visualize/cbar.gif The key features I am looking for is surfaced with grid and color, but not the terrain-like gradient. but I didn't come even close to it after browsing through rgl help file.
It is a little tricky to draw both lines and solid colours on a surface in rgl, because one will hide the other: there's no way to turn off the hidden object removal in rgl. The easiest way to do it would be to draw the grid slightly above the surface. For example, x <- seq(-2, 2, len=17) y <- seq(-2, 2, len=17) z <- outer(x,y, function(x,y) exp(-y^2)*sin(1.5*x)) color <- rainbow(41)[1+round(10*outer(x,y, function(x,y) x^2 + y^2))] persp3d(x,y,z, color=color, smooth=FALSE) surface3d(x,y,z+0.001, front="lines", back="culled") (Fiddle with the 0.001 value if the grid disappears behind the surface, or floats too high above it.) Another way would be to draw the grid (and maybe the colour) as a texture. Duncan Murdoch
have anyone drawn something like this before, is this doable afterall? thanks 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.
Thank you all for the suggestions and answers. Oliver
On Mar 12, 6:51?am, Duncan Murdoch <murd... at stats.uwo.ca> wrote:
On 11/03/2009 11:35 PM, Oliver wrote:
hi, all
I am looking at R package RGL to draw a colored mesh/surface plot like this one (from matlab). http://www.mathworks.com/access/helpdesk/help/techdoc/visualize/cbar.gif
The key features I am looking for is surfaced with grid and color, but not the terrain-like gradient. ?but I didn't come even close to it after browsing through rgl help file.
It is a little tricky to draw both lines and solid colours on a surface in rgl, because one will hide the other: ?there's no way to turn off the hidden object removal in rgl. The easiest way to do it would be to draw the grid slightly above the surface. ?For example, x <- seq(-2, 2, len=17) y <- seq(-2, 2, len=17) z <- outer(x,y, function(x,y) exp(-y^2)*sin(1.5*x)) color <- rainbow(41)[1+round(10*outer(x,y, function(x,y) x^2 + y^2))] persp3d(x,y,z, color=color, smooth=FALSE) surface3d(x,y,z+0.001, front="lines", back="culled") (Fiddle with the 0.001 value if the grid disappears behind the surface, or floats too high above it.) Another way would be to draw the grid (and maybe the colour) as a texture. Duncan Murdoch
have anyone drawn something like this before, is this doable afterall?
thanks
Oliver
______________________________________________ R-h... at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
2 days later
On 12/03/2009 6:51 AM, Duncan Murdoch wrote:
On 11/03/2009 11:35 PM, Oliver wrote:
hi, all I am looking at R package RGL to draw a colored mesh/surface plot like this one (from matlab). http://www.mathworks.com/access/helpdesk/help/techdoc/visualize/cbar.gif The key features I am looking for is surfaced with grid and color, but not the terrain-like gradient. but I didn't come even close to it after browsing through rgl help file.
It is a little tricky to draw both lines and solid colours on a surface in rgl, because one will hide the other: there's no way to turn off the hidden object removal in rgl. The easiest way to do it would be to draw the grid slightly above the surface. For example, x <- seq(-2, 2, len=17) y <- seq(-2, 2, len=17) z <- outer(x,y, function(x,y) exp(-y^2)*sin(1.5*x)) color <- rainbow(41)[1+round(10*outer(x,y, function(x,y) x^2 + y^2))] persp3d(x,y,z, color=color, smooth=FALSE) surface3d(x,y,z+0.001, front="lines", back="culled") (Fiddle with the 0.001 value if the grid disappears behind the surface, or floats too high above it.) Another way would be to draw the grid (and maybe the colour) as a texture.
I just did that, and it does look better. The texture was a simple 100x100 PNG image grid.png that was white with a black border 1 pixel wide. (Fiddle with the dimensions and border width for different weight of grid lines.) Then for 4 grid lines per unit of x and y (the same as the colour grid), do this: # First, repeat the lines above: x <- seq(-2, 2, len=17) y <- seq(-2, 2, len=17) z <- outer(x,y, function(x,y) exp(-y^2)*sin(1.5*x)) color <- rainbow(41)[1+round(10*outer(x,y, function(x,y) x^2 + y^2))] # Create texture coordinates s <- outer(x, y, function(x, y) 4*x) t <- outer(x, y, function(x, y) 4*y) # Draw with a texture persp3d(x,y,z, color=color, texture_s=s, texture_t=t,texture="grid.png", smooth=FALSE) This doesn't look good when it's small (the grid lines tend to disappear when reduced), but looks fine in large sizes. Use fatter borders or a smaller texture if you want it to look good when small. Duncan Murdoch