R/col.persp.R

col.persp <-
function(z, colfun, ncol=12, colcoe=1,
                      colrange=range(z, na.rm=T),...){
  #require(RColorBrewer)
  
  if(class(colfun)!="function") 
    stop("A color scheme function is needed for col.persp3d, such as
           topo.colors, or brewer.pal")
  
  ncolor <- ncol
  funmatch <- match.fun(colfun)
  
  couleurs  <- tail(funmatch(trunc(colcoe* ncolor), ...), ncolor)
  zlim <- colrange
  nrz <- nrow(z)
  ncz <- ncol(z)
  col      <- couleurs[trunc((z-zlim[1])/(zlim[2]-zlim[1])*(ncol-1))+1]
  fcol     <- col
  dim(fcol) <- c(nrz,ncz) #make fcol2 the corresponding matrix
  fcol      <- fcol[-nrz,-ncz]  #get rid of the last row and the last column;
  return(fcol)  
}
fzwaeustc/pcrfn documentation built on May 16, 2019, 4:06 p.m.