R/rgb2col.R

#' Convert RGB to hex
#'
#' Create hex value of colour based on RGB value
#' @param rgb Vector with \% RGB values [0;1]
#' @keywords ggplot, themes
#' @export
#' @return string
#' @examples
#' rgb(1,1,1) # returns #FFFFFF

rgb2col <- function(rgb) {
  rgb <- as.integer(rgb)
  class(rgb) <- "hexmode"
  rgb <- as.character(rgb)
  rgb <- matrix(rgb, nrow=3)
  paste("#", apply(rgb, MARGIN=2, FUN=paste, collapse=""), sep="")
}
petrbouchal/pbtools documentation built on May 25, 2019, 2:53 a.m.