R/utils.R

Defines functions pal

Documented in pal

#' Vizualize a color palette array.
#'
#' Helper to visualize palettes.  If col is named, the names of the color codes
#' will be used for the x and color scales.
#'
#' @param col character vector of color codes
#'
#' @import ggplot2
#' @export
#' @examples
#' pal(darks[3])
#' pal(darks[1])
#' pal(darks[1:2] %>% set_names(., c("b", "a")))
pal <- function(col)
{
    if (is.null(names(col))) {names(col) <- col}
    FILL_PAL <- col

    DATA <- tibble::enframe(col, name = "label", value="code")
    ggplot(DATA, aes_(x=quote(label), fill=FILL_PAL)) +
        geom_bar() +
        theme(axis.text.x=element_text(angle = 90), axis.title = element_blank(),
              axis.text.y=element_blank(), axis.ticks=element_blank()) +
        scale_fill_identity("Fill Codes:")
}
mbadge/vizR documentation built on May 27, 2019, 1:08 p.m.