knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width = 8 ) library(StrategyUnitTheme) library(ggplot2) library(tibble) library(forcats) library(dplyr)
The StrategyUnitTheme
package contains funcions that return the colours used
in the Strategy Unit's branding. This
Vignette will explain how to use these functions to set the colours in plots
created with ggplot2.
To view all of the possible colours available, you can use the following function:
su_theme_cols()
The su_theme_cols
function returns a named vectored of hex-encoded RGB values
of colours.
If you are only interested in specific colours, you can specify them as arguments to the function, like so:
su_theme_cols("orange", "red", "slate")
Or, you can use one of the available palettes:
su_theme_cols(palette = "main")
The documentation for su_theme_cols
lists all of the palettes
that are available to use.
These colours are shown below.
# note, this is not the recommended way to use the colours in a ggplot, this is # just to display the available colours colours <- su_theme_cols() tibble(name = names(colours) %>% fct_inorder() %>% fct_rev()) %>% ggplot(aes(name, fill = name)) + geom_bar() + scale_fill_manual(values = colours) + coord_flip() + theme_void() + theme(legend.position = "none", axis.text.y = element_text())
If you want to use the Strategy Unit's colours in your plots, you can use the
scale_colour_su
and scale_fill_su
functions. For example, if you wish to
use the main palette:
ggplot(iris, aes(Sepal.Length, Sepal.Width, colour = Species)) + geom_point() + scale_colour_su()
You can also change specify a different palette, and reverse the order like so:
ggplot(iris, aes(Sepal.Length, Sepal.Width, colour = Species)) + geom_point() + scale_colour_su(palette = "reds", reverse = TRUE)
These functions by default are for discrete data. If you have continuous then
you need to set the discrete
argument to FALSE
.
ggplot(faithfuld, aes(waiting, eruptions, fill = density)) + geom_tile() + scale_fill_su(discrete = FALSE, palette = "oranges", reverse = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.