gpal: Automatic palette adjustment

Description Usage Arguments Value Author(s) Examples

Description

The grattan palette from darkest to lightest given a number of colours.

Usage

1
gpal(n, dark = TRUE, reverse = FALSE)

Arguments

n

The number of variables/factors over which the palette is to paint.

dark

Should a dark palette be used? (Only available for n = 2.)

reverse

(logical) Option to reverse the palette.

Value

A vector of HTML colours to be used.

Author(s)

Hugh Parsonage

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
library(ggplot2)
dat <- data.frame(i = 1:6,
                  xmin = 1:6,
                  xmax = 1:6 + 1,
                  ymin = 0,
                  ymax = 1,
                  fill = gpal(6),
                  stringsAsFactors = FALSE) 
ggplot(dat, aes(xmin = xmin, ymin = ymin,
                xmax = xmax, ymax = ymax,
                fill = fill)) +
  geom_rect() +
  geom_text(aes(x = (xmin + xmax) / 2,
                y = (ymin + ymax) / 2,
                label = i)) +
  scale_fill_identity()
  
# Extended palette available up to 9 colours.
dat <- data.frame(i = 1:9,
                  xmin = 1:9,
                  xmax = 1:9 + 1,
                  ymin = 0,
                  ymax = 1,
                  fill = gpal(9),
                  stringsAsFactors = FALSE) 
ggplot(dat, aes(xmin = xmin, ymin = ymin,
                xmax = xmax, ymax = ymax,
                fill = fill)) +
  geom_rect() +
  geom_text(aes(x = (xmin + xmax) / 2,
                y = (ymin + ymax) / 2,
                label = i)) +
  scale_fill_identity()

HughParsonage/grattanCharts documentation built on May 8, 2019, 10:52 a.m.