colourpicker: Colours from R, Certe, Viridis and More

View source: R/colourpicker.R

colourpickerR Documentation

Colours from R, Certe, Viridis and More

Description

Colours from R, Certe, viridis and more. The output prints in the console with the actual colours.

Usage

colourpicker(x, length = 1, opacity = 0, ...)

## S3 method for class 'colourpicker'
as.character(x, ...)

## S3 method for class 'colourpicker'
print(x, ...)

add_white(x, white)

Arguments

x

colour or colour palette name. Certe colours will be used from the certe.colours object. Input can be:

  • "certe"

  • "certe0" to "certe6" (higher numbers give lighter colours)

  • "certeblauw", "certegroen", "certeroze", "certegeel", "certelila", or "certebruin" (or any of these followed by a 0 to 6)

  • "certe_sir" or "certe_sir2" for certeroze/certegeel/certegroen (will always return length 5, with names "S", "SI", "I", "IR", "R")

  • One of the colourblind-safe viridisLite palettes:

    • "viridis"

    • "magma"

    • "inferno"

    • "plasma"

    • "cividis"

    • "rocket"

    • "mako"

    • "turbo"

  • One of the built-in palettes in R (currently R 4.4.1):

    • "R3"

    • "R4"

    • "ggplot2"

    • "Okabe-Ito"

    • "Accent"

    • "Dark 2"

    • "Paired"

    • "Pastel 1"

    • "Pastel 2"

    • "Set 1"

    • "Set 2"

    • "Set 3"

    • "Tableau 10"

    • "Classic Tableau"

    • "Polychrome 36"

    • "Alphabet"

    • "topo"

    • "heatmap"

    • "rainbow"

    • "terrain"

    • "greyscale"

    • "grayscale"

  • One of the 657 built-in colours() in R, such as "azure3", "chocolate4", "darkolivegreen", "seagreen", "steelblue1"

length

size of the vector to be returned

opacity

amount of opacity (0 = solid, 1 = transparent)

...

not used at the moment

white

number between ⁠[0, 1]⁠ to add white to x

Details

Certe colours will be chosen as divergent as possible if the required output length is not too high. For example:

  • x = "certe" tries to only return the "certe" colours ("certeblauw", "certegroen", ...), the "certe3" colours ("certeblauw3", "certegroen3", ...) and the "certe5" colours ("certeblauw5", "certegroen5", ...)

  • x = "certe2" tries to only return the regular "certe2" colours ("certeblauw2", "certegroen2", ...), the "certe4" colours ("certeblauw4", "certegroen4", ...) and the "certe6" colours ("certeblauw6", "certegroen6", ...)

  • x = "certe3" tries to only return the "certe3" colours ("certeblauw3", "certegroen3", ...) and the "certe5" colours ("certeblauw5", "certegroen5", ...)

When using a single Certe colour with length > 1, a palette will be generated based on \*, \*2, \*3, \*4, and \*5. For example, colourpicker("certeblauw", 5) will return the colours "certeblauw", "certeblauw2", "certeblauw3", "certeblauw4", and "certeblauw5".

A palette from R will be expanded where needed, so even colourpicker("R4", length = 20) will work, despite "R4" only supporting a maximum of eight colours.

Value

character vector in HTML format (i.e., "#AABBCC") with new class colourpicker

Examples

colourpicker("certegroen")
colourpicker("certe", 5)
colourpicker(c("certeblauw", "red", "tan1", "#ffa", "FFAA00"))

par(mar = c(0.5, 2.5, 1.5, 0)) # set plot margins for below plots

# Certe colours
barplot(12:1,
        col = colourpicker("certe", 12),
        main = "'certe': uses 'certe' + 'certe3'")
barplot(12:1,
        col = colourpicker("certe2", 12),
        main = "'certe2': uses 'certe2' + 'certe4'")
barplot(12:1,
        col = colourpicker("certe3", 12),
        main = "'certe3': uses 'certe3' + 'certe5'")
barplot(5:1,
        col = colourpicker("certeblauw", 5),
        main = "'certeblauw'")
barplot(12:1,
        col = colourpicker("certeblauw", 12),
        main = "'certeblauw': auto-extended range")

# all colourblind-safe colour palettes from the famous viridisLite package
barplot(1:7,
        col = colourpicker("viridis", 7))
barplot(1:7,
        col = colourpicker("magma", 7))

barplot(8:1,
        col = colourpicker("R4", 8),
        main = "Some palettes have only 8 colours...")
barplot(20:1,
        col = colourpicker("R4", 20),
        main = "Not anymore!")


colours <- colourpicker("R4", 6)
colours
add_white(colours, 0.25)
add_white(colours, 0.5)
add_white(colours, 0.75)

certe-medical-epidemiology/certestyle documentation built on July 12, 2024, 2:45 p.m.