R/display_carto_pal.R

Defines functions display_carto_pal

Documented in display_carto_pal

#' CARTOcolor palette viewer
#'
#' Displays a color palette from CARTOcolor
#'
#' @param n Number of different colors in the palette, minimum depending on palette (2 or 3), maximum depending on palette (7 or 11)
#' @param name A palette name
#'
#' @importFrom graphics image
#'
#' @examples
#' display_carto_pal(7, "Burg")
#'
#' @export
display_carto_pal = function(n = NULL, name){
        selected_colors = carto_pal(n, name)
        selected_type = rcartocolor::cartocolors[rcartocolor::cartocolors$Name == name, "Type"][[1]]
        image(1:n, 1, as.matrix(1:n), col = selected_colors,
              main = paste0(name, ": ", selected_type, " (", n ,")"),
              xlab = " ", ylab = " ", xaxt = "n", yaxt = "n", bty="n")
}

Try the rcartocolor package in your browser

Any scripts or data that you put into this service are public.

rcartocolor documentation built on May 31, 2023, 9:16 p.m.