mncolors: MN color palette maps

View source: R/mncolors.R

mncolorsR Documentation

MN color palette maps

Description

This function creates a vector of n equally spaced colors along a MN color palette.

Usage

mncolors(n, palette = "primary", alpha = 1, begin = 0, end = 1, direction = 1)

primary(n, alpha = 1, begin = 0, end = 1, direction = 1)

Arguments

n

The number of colors (\ge 1) to be in the palette.

palette

A character string indicating the MN palette. The options available are: "primary", "accent", "extended", "blue", "green", "gray", "safety", "primary_accent", "primary_extended", "primary_accent_extended", "corn", "treefrog", and "crayfish".

alpha

The alpha transparency, a number in [0,1], see argument alpha in hsv.

begin

The (corrected) hue in [0,1] at which the colormap begins.

end

The (corrected) hue in [0,1] at which the colormap ends.

direction

Sets the order of colors in the scale. If 1, the default, colors are ordered from darkest to lightest. If -1, the order of colors is reversed.

Details

Here are the color scales:

mncolors-scales.png

Semi-transparent colors (0 < alpha < 1) are supported only on some devices: see rgb.

Value

mncolors returns a character vector, cv, of color hex codes. This can be used either to create a user-defined color palette for subsequent graphics by palette(cv), a col = specification in graphics functions or in par.

Author(s)

Dorian Kvale: @state.mn.us, @MN Style Guide

Examples

library(ggplot2)
library(hexbin)

dat <- data.frame(x = rnorm(10000), y = rnorm(10000))

ggplot(dat, aes(x = x, y = y)) +
  geom_hex() + coord_fixed() +
  scale_fill_gradientn(colors = mncolors(256, palette = "primary_extended"))

# using code from RColorBrewer to demo the palette
n = 200
image(
  1:n, 1, as.matrix(1:n),
  col = mncolors(n, palette = "blue"),
  xlab = "mncolors n", ylab = "", xaxt = "n", yaxt = "n", bty = "n"
)

MPCA-data/mncolors documentation built on Feb. 3, 2024, 11:37 a.m.