Skip to contents

Easy way to view the created palette

Usage

view_palette(
  monochrome_palette,
  view_labels = TRUE,
  view_contrast = TRUE,
  contrast_colours = c("black", "white"),
  ...
)

Arguments

monochrome_palette

Vector of hex colour codes and/or colour names, or a generate_palette() call.

view_labels

Logical. Whether or not the hex colour codes are shown on the palette displayed in the plot window.

view_contrast

Logical. If view_labels is TRUE, view_contrast = TRUE (the default) adds the WCAG contrast ratio to each label: each label shows the colour's contrast ratio with the colour the label is written in (e.g. "vs black"). A title explains what to aim for: a contrast over 7:1 for text and over 3:1 for shapes. See contrast_ratio(). Ratios are rounded down to one decimal place, so they never overstate the contrast (e.g. 4.49:1 is shown as 4.4:1, not 4.5:1). Changing view_contrast or contrast_colours from their defaults with view_labels = FALSE gives a message, as they have no effect.

contrast_colours

The colours the labels are written in, and that the contrast ratios are calculated against: one or two recognised colour names and/or hex colour codes. Defaults to c("black", "white"). The first colour's labels are shown above the middle of each colour, and the second's below. Labels say "vs" and the colour as you gave it (e.g. "vs #2C3D4F"), or its name if you name the vector, e.g. c(text = "#2C3D4F", background = "#F5F0E6"). As contrast works both ways, a label written in your plot's background colour shows how well shapes in each colour would stand out against that background.

...

contrast_colors, the US spelling of contrast_colours. Other argument names give an error.

Value

A plot showing all the colours in the palette on the same row

Font

Text is shown in Karla, which is bundled with the package, when the plot is created for a graphics device that supports it: ragg devices (including RStudio's AGG backend) and svglite. On other devices, such as pdf(), the device's default font is used. To choose the font yourself, set options(monochromeR.font = "Karla"), or options(monochromeR.font = "") for the device default. If you save a Karla plot as a PDF, use ggplot2::ggsave(..., device = grDevices::cairo_pdf).

Examples

view_palette(c("#464E69", "#8C90A1", "#D1D2D9"))

view_palette(
  c("unripe" = "#89973d", "ripe" = "#e8b92f", "overripe" = "#a45e41")
)

view_palette(generate_palette("pink", "go_darker", n_colours = 3))

view_palette(c("#464E69", "#8C90A1", "#D1D2D9"), view_contrast = FALSE)

view_palette(
  c("#464E69", "#8C90A1", "#D1D2D9"),
  contrast_colours = c(text = "#2C3D4F", background = "#F5F0E6")
)