perLightness = function(x){
L = (100 * 0.5 * (max(col2rgb(x)) + min(col2rgb(x)))) / 255
L
}
#' getNKIPal
#'
#' @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.}
#' }
getNKIPal = function(vector = T, plot = F){
NKIpal = c('AVLyellow' = '#fbc81c', 'AVLred' = '#ba2340', 'AVLgray' = '#999999')
if(plot){
df = data.frame(xx = rep(names(NKIpal), each = 500),
yy = rep(c(1,1,1), each = 500),
state = factor(names(NKIpal)[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 = (NKIpal))+
geom_jitter() +
guides(col = F) +
theme( axis.title = element_blank(),
axis.ticks = element_blank()) +
ggtitle('The Netherlands Cancer Institute')+
scale_y_continuous(breaks = NULL)
print(G)
}
coldf = cbind(names(NKIpal),
as.data.frame(NKIpal),unlist(lapply(NKIpal, perLightness)))
colnames(coldf) = c('name', 'hex','lightness')
rownames(coldf) = NULL
if(vector){
return(as.character(unname(coldf$hex)))
} else {
return(coldf)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.