scale_gov: Discrete colour scales using the gov_cols palette

Description Usage Arguments Value Examples

View source: R/scale_gov.R

Description

scale_gov provides a means to easily use the gov_cols palette in charts. It applies the palette in order as an unnamed vector.

Usage

1
scale_gov(type = "fill", ...)

Arguments

type

sets whether the scale applies to (line) colour, the fill colour, or both.

...

additional arguments to be supplied to the underlying ggplot2 scale_ function.

Value

Will not return anything of itself, but when used in conjuntion with ggplot and (e.g.) geom_col from the package ggplot2, will apply a colour scale to a plot.

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
library(ggplot2)
library(govstyle)
library(dplyr)

df <- data.frame(
    group = c("apple", "apple", "apple", "pear", "pear", "pear"),
    year = c(2009, 2010, 2011, 2009, 2010, 2011),
    price = c(35, 37, 36, 24, 25, 28))

# Column chart
ggplot(df, aes(x = year, y = price, fill = group)) +
   geom_col(position = "dodge") +
   theme_gov() +
   scale_gov("fill")

# Line chart
ggplot(df, aes(x = year, y = price, colour = group)) +
   geom_line(size = 2) +
   theme_gov() +
   scale_gov("colour")

# Point chart, with filled points (black outline)
ggplot(df, aes(x = year, y = price, colour = group)) +
   geom_line() +
   geom_point(shape = 21, size = 4, stroke = 1, fill = "#ffffff") +
   theme_gov() +
   scale_gov("colour") +
   ylim(0,40)

ukgovdatascience/govstyle documentation built on Oct. 8, 2019, 7:39 p.m.