[R] Color facets by z-level (solved by creating example)

David Winsemius
2010-03-10T20:52:00Z

I am having trouble getting my facets colored with "concentric" colors
by z level. This code give a fair representation of my problems
dealing a real dataset

  cmtx <- matrix(, nrow=10, ncol=10)
  cc <- (row(cmtx)-5)^2 + (col(cmtx)-5)^2
  cc
#----------
       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  [1,]   32   25   20   17   16   17   20   25   32    41
  [2,]   25   18   13   10    9   10   13   18   25    34
  [3,]   20   13    8    5    4    5    8   13   20    29
  [4,]   17   10    5    2    1    2    5   10   17    26
  [5,]   16    9    4    1    0    1    4    9   16    25
  [6,]   17   10    5    2    1    2    5   10   17    26
  [7,]   20   13    8    5    4    5    8   13   20    29
  [8,]   25   18   13   10    9   10   13   18   25    34
  [9,]   32   25   20   17   16   17   20   25   32    41
[10,]   41   34   29   26   25   26   29   34   41    50
#-----------

ccut <- cut(cc, breaks=c(0, 2, 4, 8, 16, 50))
persp(cc, ticktype="detailed",
          zlim=c(0,25), col= palette(rainbow(6))[as.numeric(ccut)],
phi=40)

Also tried setting ccut up as a matrix:

 > ccut <- as.matrix(as.numeric(cut(cc, breaks=c(0, 2, 4, 8, 16,
32)) ), nrow=nrow(cmtx) )
 > persp(cc, ticktype="detailed", zlim=c(0,25), col=
palette(rainbow(6))[(ccut)], phi=40)

The colors are not arranged in the same fashion as the facets. I'm
trying to get concentric coloring by z level.  I know I have seen this
solution before and thought I had remembered the steps but am clearly
not geting it. Advice?

Never mind. Setting the problem up this way let me try one last
(successful) strategy:

persp(cc, ticktype="detailed", zlim=c(0,25), col= palette(rainbow(5))
[ccut[-1,-1] ], phi=40)

The facets are described in the help page as being (nx-1)*(ny-1) in
number, so this should have triggered this sooner. Perhaps this effort
will be of some use to another challenged soul.


David Winsemius, MD
West Hartford, CT