Re: [R] How to put different color in some portion of a surface plot?

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Tue, 06 May 2008 10:52:14 -0400

On 5/6/2008 10:31 AM, Megh Dal wrote:
> Hi all,
>
> I have following problem :
>
> a = b = seq(1, 50000, by=500)
> v = matrix(0, nrow=length(a), ncol=length(a))
> for (i in 1:length(a))
> {
> for (j in 1:length(a))
> {
> d = c(17989*a[i], -18109*b[j])
> v[i,j] = t(d) %*% matrix(c(0.0001741, 0.0001280, 0.0001280, 0.0002570), nrow=2) %*% d
> }
> }
> library("rgl")
> open3d()
> persp3d(a,b,v,col="green",alpha=0.7,aspect=c(1,1,0.5))
>
>
> Now I want to shed the portion with different color of the surface which satisfy following condition:
>
> 0 < (a-b) < max(a)
>
> Can anyone please tell me how to do that?

The col option can be a matrix of the same shape as v, giving the colour at each vertex. (Note that this is different from persp(), which gives the colour in each cell, i.e. one less in each dimension. The persp3d man page tells how to duplicate the persp() behaviour.)

For example,

shade <- outer(a, b, function(x,y) (0 < (x-y)) & ((x-y) < max(a))) persp3d(a,b,v,col=ifelse(shade, "red", "green"),

         alpha=0.7,aspect=c(1,1,0.5))

Duncan Murdoch



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. Received on Tue 06 May 2008 - 15:22:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 06 May 2008 - 15:30:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive