David Schellenberger Costa
2013-Mar-05 11:28 UTC
[R] different colors for two wireframe spheres
Dear List, I have the code below adapted from the lattice-package examples to draw two spheres. I would now like to give both different surface colors, e.g. one red and one blue. ## 3-D surface parametrized on a 2-D grid n <- 10 tx <- matrix(seq(-pi, pi, length.out = 2*n), 2*n, n) ty <- matrix(seq(-pi, pi, length.out = n) / 2, 2*n, n, byrow = T) xx <- cos(tx) * cos(ty) yy <- sin(tx) * cos(ty) zz <- sin(ty) zzz <- zz bxx <- xx+5 byy <- yy+5 bzzz <- zzz+5 xx=rbind(xx,rep(NA,n),bxx) yy=rbind(yy,rep(NA,n),byy) zzz=rbind(zzz,rep(NA,n),bzzz) gr<-rbind(matrix(1,n,2*n),rep(NA,n),matrix(2,n,2*n)) wireframe(zzz ~ xx + yy, groups=gr,col.groups=c("red","blue")) I tried various parameters as col.groups, col.regions but I have the impression that the "groups" argument in the wireframe command can only be used when supplying a data argument, which does not allow to plot the spheres as far as I tried. Is there a solution for this? Cheers David Schellenberger
On Mar 5, 2013, at 3:28 AM, David Schellenberger Costa wrote:> Dear List, > > I have the code below adapted from the lattice-package examples to draw two spheres. I would now like to give > both different surface colors, e.g. one red and one blue. > > ## 3-D surface parametrized on a 2-D grid > > n <- 10 > > tx <- matrix(seq(-pi, pi, length.out = 2*n), 2*n, n) > ty <- matrix(seq(-pi, pi, length.out = n) / 2, 2*n, n, byrow = T) > xx <- cos(tx) * cos(ty) > yy <- sin(tx) * cos(ty) > zz <- sin(ty) > zzz <- zz > > bxx <- xx+5 > byy <- yy+5 > bzzz <- zzz+5 > > xx=rbind(xx,rep(NA,n),bxx) > yy=rbind(yy,rep(NA,n),byy) > zzz=rbind(zzz,rep(NA,n),bzzz) > gr<-rbind(matrix(1,n,2*n),rep(NA,n),matrix(2,n,2*n)) > > wireframe(zzz ~ xx + yy, groups=gr,col.groups=c("red","blue"))You might try: wireframe(zzz ~ xx + yy, groups=gr, drape=TRUE ) Notice that in help(wireframe): Details you find a sentence: "Note that this feature does not work with groups, subscripts, subset, etc. Conditioning variables are also not supported in this case." This sentence refers back to the paragraph beginning "For single panel plots, wireframe can also plot parametrized 3-D surfaces..." that describes the method you are using to draw those spheres.> > I tried various parameters as col.groups, col.regions but I have the impression that the "groups" argument in the wireframe command can only be used when supplying a data argument, which does not allow to plot the spheres as far as I tried. Is there a solution for this? > > Cheers > > David Schellenberger > ______________________________________________ > 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.David Winsemius Alameda, CA, USA