https://github.com/cran/kohonen
Raw File
Tip revision: f81877bc7683e133eabd1ffd964824bad9a901ac authored by Ron Wehrens on 28 March 2011, 00:00:00 UTC
version 2.0.7
Tip revision: f81877b
tricolor.R
tricolor <- function(grid,
                     phis = c(0, 2*pi/3, 4*pi/3), # default RGB
                     offset = 0) {
  if (offset < 0 | offset > .9)
    stop("Illegal offset value, should be in [0, .9]")
  
  rgbs <- matrix(0, nrow(grid$pts), 3)
  for (i in seq(along=phis)) {
    Rmat <- matrix(c(cos(phis[i]), sin(phis[i]), -sin(phis[i]), cos(phis[i])),
                   2, 2)
    X <- grid$pts %*% Rmat
    rgbs[,i] <- X[,2]
  }

  rgbs <- sweep(rgbs, 2, apply(rgbs, 2, min), FUN = "-")
  maxima <- apply(rgbs, 2, max) / (1 - offset)

  sweep(rgbs, 2, maxima, FUN = "/") + offset
}
back to top