scale_colour_dft: Extract named palette colours as hex codes for use in line...

View source: R/scaleXDft.R

scale_colour_dftR Documentation

Extract named palette colours as hex codes for use in line charts

Description

Function to use custom DfT palettes for line colours in ggplot charts

Usage

scale_colour_dft(palette = "electric.brights", gradient = FALSE, ...)

Arguments

palette

Named DfT palette to use in line colours. Defaults to "electric.brights"

gradient

Boolean response whether to use gradient palette instead of standard palettes. Defaults to false.

...

Other arguments to pass to extract gradients function

Examples

## Simple line plot using default palette

library(ggplot2)

df <- economics_long[economics_long$variable %in% c("psavert", "uempmed"), ]

# plot
ggplot(df, aes(x=date)) +
  geom_line(aes(y=value, col=variable), size = 1) +
  scale_colour_dft()+
  theme(axis.text.x = element_text(angle = 90, vjust=0.5, size = 8))  # turn off minor grid
## More complex line plot using full range of colours in palette

library(ggplot2)

df <- data.frame(supp=rep(c("VC1", "OJ", "VC2", "OJ2"), each=3),
                 dose=rep(c("D0.5", "D1", "D2"), 4),
                 len=c(6.8, 15, 33, 4.2, 10, 29.5, 3.6, 11, 21, 2, 8, 16))

# plot
ggplot(df, aes(x=dose, y=len, colour=supp, group = supp)) +
  geom_line(size = 1) +
  scale_colour_dft(palette = "electric.brights")+
  theme(axis.text.x = element_text(angle = 90, vjust=0.5, size = 8))  # turn off minor grid

department-for-transport/dftplotr documentation built on April 3, 2024, 3:55 p.m.