suresh
2010-Nov-26 10:21 UTC
[R] 3D-surface colour based on the values of X or Y data points
Dear R-experts, Using persp3d(), I plotted a 3d surface. I would like to colour this surface based on the result values (dependent variable) grouped in, say, three to five different ranges. Later, I would also like to paint the same surface based on the range-values of one of the independent variables. Please help. Thank you. Regards, Suresh -- View this message in context: http://r.789695.n4.nabble.com/3D-surface-colour-based-on-the-values-of-X-or-Y-data-points-tp3060018p3060018.html Sent from the R help mailing list archive at Nabble.com.
Duncan Murdoch
2010-Nov-26 11:34 UTC
[R] 3D-surface colour based on the values of X or Y data points
On 26/11/2010 5:21 AM, suresh wrote:> > Dear R-experts, > > Using persp3d(), I plotted a 3d surface. I would like to colour this surface > based on the result values (dependent variable) grouped in, say, three to > five different ranges. Later, I would also like to paint the same surface > based on the range-values of one of the independent variables. > Please help. > > Thank you. > > Regards, > Suresh >On 26/11/2010 5:21 AM, suresh wrote: > > Dear R-experts, > > Using persp3d(), I plotted a 3d surface. I would like to colour this surface > based on the result values (dependent variable) grouped in, say, three to > five different ranges. Later, I would also like to paint the same surface > based on the range-values of one of the independent variables. > Please help. You can specify a matrix of colours of the same shape as z. It will be used to specify the colour at each vertex of the mesh that is shown, and colours will be interpolated between vertices. Sharp edges are harder, because it's ambiguous where the change should occur. For those, you'll need to plot surfaces one colour at a time, setting the z values for other colours to NA so they aren't plotted. The vertices at colour boundaries will need to be plotted twice. For example: x <- y <- seq(-1,1,len=20) z <- outer(x, y, function(x,y) x^2 + y^2) # smooth changes first colour <- ifelse(z < 1/2, "red", "white") persp3d(x,y,z, col=colour) # sharp edges next open3d() redvals <- ifelse(z < 1/2, z, NA) surface3d(x, y, redvals, col="red") # overplotting will not be shown since the x,y and z values are # identical; only the empty areas will show as white surface3d(x, y, z, col="white") # now draw the box decorate3d()
suresh
2010-Nov-26 12:13 UTC
[R] 3D-surface colour based on the values of X or Y data points
Ok. So, I assume that colours based on the value-range of independent variables would be similar. Will try.. -- View this message in context: http://r.789695.n4.nabble.com/3D-surface-colour-based-on-the-values-of-X-or-Y-data-points-tp3060018p3060162.html Sent from the R help mailing list archive at Nabble.com.