safeBrew: Allows RColorBrew to handle n values less than 3 and greater...

View source: R/misc_helpers.R

safeBrewR Documentation

Allows RColorBrew to handle n values less than 3 and greater than 8 without warnings and return expected number of colors.

Description

For convenience, instead of the number n requested, n may be a character or factor vector and outputs will be appropriately named for use with scale_color/fill_manual.

Usage

safeBrew(n, pal = "Dark2")

Arguments

n

integer value of number of colors to make palette for. Alternatively a character or factor, in which case palette will be generated for each unique item or factor level repsectively.

pal

palette recognized by RColorBrewer

Details

Additionally, accepts pal as "gg", "ggplot", or "ggplot2" to reproduce default ggplot colors in the same way.

Value

a character vector of hex coded colors of length n from the color brewer palette pal. If n is supplied as character or factor, output will be named accordingly.

Examples

plot(1:2, rep(0, 2),  col = safeBrew(2, "dark2"), pch = 16, cex = 6)
plot(1:12, rep(0, 12),  col = safeBrew(12, "set1"), pch = 16, cex = 6)
plot(1:12, rep(0, 12),  col = safeBrew(12, "set2"), pch = 16, cex = 6)
plot(1:12, rep(0, 12),  col = safeBrew(12, "set3"), pch = 16, cex = 6)

jrboyd/seqsetvis documentation built on March 17, 2024, 3:14 p.m.