R/utils.R

Defines functions getColorsFromNumbers

Documented in getColorsFromNumbers

###############################################
# Auxillary functions
###############################################


#' @title Get colors for numeric vector values
#' @description Function to convert numbers into colors.
#'
#' @param x A numeric vector of values.
#' @param colors A vector of colors for the palette.
#' @param range A range of values for color picking.
#' 
#' @return Returns a vector with colors.
#'
#' @author Mikhail Churakov (\email{mikhail.churakov@@pasteur.fr}).
#' 
#' @export
getColorsFromNumbers <- function(x, colors = c("blue", "white", "red"), range = range(x)) {
  mColors <- colorRamp(colors)((x - min(range)) / (max(range) - min(range)))
  return(rgb(mColors[, 1] / 255, mColors[, 2] / 255, mColors[, 3] / 255))
}
mc30/wasp documentation built on Sept. 14, 2020, 4:20 a.m.