#' A PJO palette generator
#'
#'
#' @param n Number of colors desired.
#' @param name Name of desired palette.
#' @return A vector of colours.
#' @export
#' @keywords colors
view_pjo_palette <- function(name, n) {
pal <- pjo_palettes[[name]]
if (is.null(pal))
stop("Palette not found.")
if (missing(n)) {
n <- length(pal)
}
if (n > length(pal)) {
stop("Number of requested colors greater than what palette can offer")
}
out <- pal[1:n]
structure(out, class = "palette", name = name)
}
#' @export
#' @importFrom graphics rect par image text
#' @importFrom grDevices rgb
print.palette <- function(x, ...) {
n <- length(x)
old <- par(mar = c(0.5, 0.5, 0.5, 0.5))
on.exit(par(old))
image(1:n, 1, as.matrix(1:n), col = x,
ylab = "", xaxt = "n", yaxt = "n", bty = "n")
rect(0, 0.9, n + 1, 1.1, col = rgb(1, 1, 1, 0.8), border = NA)
text((n + 1) / 2, 1, labels = attr(x, "name"), cex = 1, family = "sans", col = "#32373D")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.