oe_palette: An Oxford Economics palette generator

View source: R/colors.R

oe_paletteR Documentation

An Oxford Economics palette generator

Description

Color palettes based on the OE style guide

Usage

oe_palette(name, n, type = c("discrete", "continuous"))

Arguments

name

Name of desired palette. Choices are: primary, secondary, blue_grad, bold, pale

n

Number of colors desired.

type

Either "continuous" or "discrete". Use continuous if you want to automatically interpolate between colours.

Value

A vector of colours.

Examples

# If you need more colours than normally found in a palette, you
# can use a continuous palette to interpolate between existing
# colours
pal <- oe_palette("secondary", 21, type = "continuous")
image(volcano, col = pal)

# We can't directly feed the palette into scale_fill_manual because
# the colors are named in the vector. If one provides scale_fill_manual
# a named vector, then ggplot2 is trying to match the colors to the
# values in the dataframe

# One approach: Just directly assign from the palette
ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) +
  geom_point(size = 4) +
  scale_colour_manual(values = c(
    "setosa"=oe_palettes$primary[["prime_blue"]],
    "virginica"=oe_palettes$primary[["prime_grey"]],
    "versicolor"=oe_palettes$primary[["prime_ltgrey"]]))

# Another approach: Create vector of colors by selecting palette, extract
# specific colors, and unname
cols <- oe_palette("primary")[c("prime_blue", "prime_ltgrey")] %>%
 unname()
ggplot(mtcars, aes(factor(cyl), fill=factor(vs))) +  geom_bar() +
 scale_fill_manual(values = cols)

# Another approach: Create vector of colors by seleting palette and unname
# it
cols <- unname(oe_palette("primary"))
ggplot(mtcars, aes(factor(cyl), fill=factor(vs))) +  geom_bar() +
 scale_fill_manual(values = cols)

# Another approach: Create vector of colors and then set names (e.g.
# to match dataframe values)
cols <- oe_palette("primary")[c("prime_blue", "prime_ltgrey")] %>%
 setNames(c("1", "0"))
ggplot(mtcars, aes(factor(cyl), fill=factor(vs))) +  geom_bar() +
 scale_fill_manual(values = cols)


TourismEconomics/oebrand documentation built on April 26, 2022, 3:49 p.m.