R/getEelsPal.R

perLightness = function(x){
  L = (100 * 0.5 * (max(col2rgb(x)) + min(col2rgb(x)))) / 255
  L
}

#' getEelsPal
#'
#' Get the color pallette of the Parramatta Eels
#'
#' @param vector only return a unnamed vector
#' @param plot Plot a simple plot to showcase the colors
#' @return A df:
#' \itemize{
#'  \item{name: }{The categories of the colours.}
#'  \item{hex: }{The hex-values of the colours.}
#'  \item{lightness: }{The perceived lightness of the colours.}
#' }
getEelsPal = function(vector = T,plot = F){

  eelsPal = c(yellow = '#ffd327',
              blue = '#006eb5',
              green = '#90c84bff')

  if(plot){
    df = data.frame(xx = rep(names(eelsPal), each = 500),
                    yy = rep(c(1,1,1), each = 500),
                    state = factor(names(eelsPal)[rep(c(1,2,3), each = 500)]))

    require(ggplot2)
    require(RHWlib)
    G = ggplot(df, aes(x=xx,y=yy,col = (state))) +
      RHWlib::RHWtheme() +
      scale_colour_manual(values = (eelsPal))+
      geom_jitter() +
      guides(col = F) +
      theme( axis.title = element_blank(),
            axis.ticks = element_blank()) +
      ggtitle('Parramatta Eels')+
      scale_y_continuous(breaks = NULL)
    print(G)
  }

  coldf = cbind(names(eelsPal),
                as.data.frame(eelsPal),unlist(lapply(eelsPal, perLightness)))
  colnames(coldf) = c('name', 'hex','lightness')
  rownames(coldf) = NULL

  if(vector){
    return(as.character(unname(coldf$hex)))
  } else {
    return(coldf)
  }
}
robinweide/RHWlib documentation built on May 7, 2019, 8:03 a.m.