contrast_cols: Contrasting colors

View source: R/colors.R

contrast_colsR Documentation

Contrasting colors

Description

Making contrasting colors for use in bar charts.

Usage

contrast_cols(n_colors = 3, palette1 = "Pastel 1", palette2 = "Dark 3")

Arguments

n_colors

The number of colors you want (integer).

palette1

A qualitative HCL palette from the colorspace package.

palette2

A qualitative HCL palette from the colorspace package.

Details

The default colors used by ggplot2 are too similar for neighboring sectors in bar charts, making it difficult to see where one sector ends and the next starts.

This function creates an alternative vector of colors, by using two different palettes, going from lighter to darker colors, then reverse one of them and finally mixing them taking every second color from each. This mean any two neighboring colors are quite distinct from each other.

You may change the colors by supplying alternative qualitative HCL palettes from the colorspace package, see the vignette of this package for more on what you may choose.

Value

A vector of length n_colors with colors.

Author(s)

Lars Snipen.


larssnip/midiv documentation built on Jan. 20, 2025, 6:22 p.m.