R/transp.R

#' make colours in plots transparent
#'
#' \code{transp(colour,alpha)}
#'
#' @param colours colour or vector of colours
#' @param alpha is opaqueness on a scale of 0 to 100. A single value or the same
#' number of values as there are colours.

#' @details best to set up your palette and use numbers: ..col=transp(1:3,c(20,70,10))..

transp=function(colour,alpha){
  LC=length(colour)
  if (length(alpha)==1)(alpha=rep(alpha,LC))
  if (length(alpha)!=LC){
    print('wrong number of transparency values',quote=F)
  } else {
    X=NULL
    for(a in 1:LC){
      Y=rgb(col2rgb(colour)[1,a]/255,col2rgb(colour)[2,a]/255,col2rgb(colour)[3,a]/255,alpha[a]/100)
      X=c(X,Y)
    }
    return(X)
  }}
helophilus/ColsTools documentation built on May 30, 2019, 4:03 p.m.