| Title: | Graphic Styles and Colours for Scottish Government Plots |
|---|---|
| Description: | A 'ggplot2' theme and colour palettes to create accessible data visualisations in the Scottish Government. |
| Authors: | Scottish Government [cph, fnd], Alice Hannah [aut, cre] |
| Maintainer: | Alice Hannah <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.5.0.9000 |
| Built: | 2026-05-13 08:24:42 UTC |
| Source: | https://github.com/scotgovanalysis/sgplot |
af_colour_values is a vector containing colour names and their
corresponding hex codes.
af_colour_palettes is a list grouping colours into palettes.
af_colour_values af_colour_palettesaf_colour_values af_colour_palettes
An object of class character of length 9.
An object of class list of length 5.
Government Analysis Function Colours Guidance # nolint: line_length_linter.
Available palettes and palette types
available_palettes(palette_type, error_call = rlang::caller_env()) available_palette_types()available_palettes(palette_type, error_call = rlang::caller_env()) available_palette_types()
palette_type |
String. |
error_call |
Environment to reference in error messages. |
A character vector of available palettes or palette types.
available_palette_types() available_palettes("sg")available_palette_types() available_palettes("sg")
Checks values against those available in
available_palette_types() and available_palettes().
check_palette(palette_type, palette, error_call = rlang::caller_env()) check_palette_type(palette_type, error_call = rlang::caller_env())check_palette(palette_type, palette, error_call = rlang::caller_env()) check_palette_type(palette_type, error_call = rlang::caller_env())
palette_type, palette
|
String. |
error_call |
Environment to reference in error messages. |
The value being checked is returned invisibly if the check is successful. Otherwise the function will return an error.
check_palette_type("sg") check_palette("sg", "main")check_palette_type("sg") check_palette("sg", "main")
Convert millimetres to inches
mm_to_inch(x)mm_to_inch(x)
x |
Numeric value in millimetres |
A numerical value in inches
mm_to_inch(100)mm_to_inch(100)
Continuous colour/fill scales for Scottish Government plots
scale_colour_continuous_sg( palette = "sequential", palette_type = "sg", reverse = FALSE, na.value = "grey50", guide = "colourbar", ..., na_colour = deprecated() ) scale_fill_continuous_sg( palette = "sequential", palette_type = "sg", reverse = FALSE, na.value = "grey50", guide = "colourbar", ..., na_colour = deprecated() )scale_colour_continuous_sg( palette = "sequential", palette_type = "sg", reverse = FALSE, na.value = "grey50", guide = "colourbar", ..., na_colour = deprecated() ) scale_fill_continuous_sg( palette = "sequential", palette_type = "sg", reverse = FALSE, na.value = "grey50", guide = "colourbar", ..., na_colour = deprecated() )
palette |
Name of palette to use; e.g. "main", "sequential", "focus". Default value is "sequential". |
palette_type |
Name of palette type to use. Defaults to "sg". For all
available palette types, run |
reverse |
Boolean value to indicate whether the palette should be reversed. |
na.value |
Colour to set for missing values. |
guide |
A name or function used to create guide. Default is "colourbar". |
... |
Additional arguments passed to scale type. |
na_colour |
ggplot2 continuous colour/fill scale
library(ggplot2) ggplot(mtcars, aes(x = mpg, y = wt, colour = cyl)) + geom_point() + scale_colour_continuous_sg() ggplot(faithfuld, aes(x = waiting, y = eruptions, fill = density)) + geom_raster() + scale_fill_continuous_sg()library(ggplot2) ggplot(mtcars, aes(x = mpg, y = wt, colour = cyl)) + geom_point() + scale_colour_continuous_sg() ggplot(faithfuld, aes(x = waiting, y = eruptions, fill = density)) + geom_raster() + scale_fill_continuous_sg()
Discrete colour/fill scales for Scottish Government plots
scale_colour_discrete_sg( palette = "main", palette_type = "sg", reverse = FALSE, ... ) scale_fill_discrete_sg( palette = "main", palette_type = "sg", reverse = FALSE, ... )scale_colour_discrete_sg( palette = "main", palette_type = "sg", reverse = FALSE, ... ) scale_fill_discrete_sg( palette = "main", palette_type = "sg", reverse = FALSE, ... )
palette |
Name of palette to use; e.g. "main", "sequential", "focus". Default value is "main". |
palette_type |
Name of palette type to use. Defaults to "sg". For all
available palette types, run |
reverse |
Boolean value to indicate whether the palette should be reversed. |
... |
Additional arguments passed to scale type. |
ggplot2 discrete colour/fill scale
library(ggplot2) library(dplyr) economics_long %>% filter(variable %in% c("psavert", "uempmed")) %>% ggplot(aes(x = date, y = value, colour = variable)) + geom_line(linewidth = 1) + scale_colour_discrete_sg() d <- subset(mpg, manufacturer == "ford") ggplot(d, aes(x = class, fill = class)) + geom_bar() + scale_fill_discrete_sg()library(ggplot2) library(dplyr) economics_long %>% filter(variable %in% c("psavert", "uempmed")) %>% ggplot(aes(x = date, y = value, colour = variable)) + geom_line(linewidth = 1) + scale_colour_discrete_sg() d <- subset(mpg, manufacturer == "ford") ggplot(d, aes(x = class, fill = class)) + geom_bar() + scale_fill_discrete_sg()
sg_colour_values is a vector containing colour names and their
corresponding hex codes.
sg_colour_palettes is a list grouping colours into palettes.
sg_colour_values sg_colour_palettessg_colour_values sg_colour_palettes
An object of class character of length 11.
An object of class list of length 4.
Scottish Government Design System # nolint: line_length_linter.
sss_colour_values is a vector containing colour names and their
corresponding hex codes.
sss_colour_palettes is a list grouping colours into palettes.
sss_colour_values sss_colour_palettessss_colour_values sss_colour_palettes
An object of class character of length 12.
An object of class list of length 4.
Contact the Social Security Scotland Statistics mailbox # nolint: line_length_linter. with any queries about these colours and palettes.
ggplot2 theme for Scottish Government plots.
theme_sg( base_size = 12, base_line_size = base_size/24, base_rect_size = base_size/24, grid = c("y", "x", "xy", "none"), axis = c("x", "y", "xy", "none"), ticks = c("xy", "x", "y", "none"), legend = c("right", "left", "top", "bottom", "none") )theme_sg( base_size = 12, base_line_size = base_size/24, base_rect_size = base_size/24, grid = c("y", "x", "xy", "none"), axis = c("x", "y", "xy", "none"), ticks = c("xy", "x", "y", "none"), legend = c("right", "left", "top", "bottom", "none") )
base_size |
base font size, given in pts. |
base_line_size |
base size for line elements. |
base_rect_size |
base size for rect elements. |
grid, axis, ticks
|
'x', 'y', 'xy' or 'none' to determine for which axes the attribute should be drawn. Grid defaults to 'y', axis to 'x', and ticks to 'xy'. |
legend |
'right', 'left', 'top', 'bottom', or 'none' to determine the position of the legend. Defaults to 'right'. |
ggplot2 theme
library(ggplot2) p <- ggplot(mpg, aes(x = class)) + geom_bar() p p + theme_sg()library(ggplot2) p <- ggplot(mpg, aes(x = class)) + geom_bar() p p + theme_sg()
Set sgplot theme, colour palette and geom aesthetic defaults for ggplot2 charts.
use_sgplot( palette_type = "sg", quietly = FALSE, ..., default_colour = deprecated() )use_sgplot( palette_type = "sg", quietly = FALSE, ..., default_colour = deprecated() )
palette_type |
Name of palette type to use. Defaults to "sg". For all
available palette types, run |
quietly |
Should the function run quietly? By default, |
... |
Arguments passed to |
default_colour |
NULL. Function is used for side effects of setting default ggplot2 theme, colour palette and geom aesthetics.
library(ggplot2) d <- subset(mpg, manufacturer == "ford") # ggplot2 defaults ggplot(d, aes(x = model)) + geom_bar() ggplot(d, aes(x = model, fill = class)) + geom_bar() # Use sgplot defaults use_sgplot() ggplot(d, aes(x = model)) + geom_bar() ggplot(d, aes(x = model, fill = class, colour = class)) + geom_bar() # Use sgplot defaults and Social Security Scotland colour palettes use_sgplot(palette_type = "sss") ggplot(d, aes(x = model)) + geom_bar() ggplot(d, aes(x = model, fill = class, colour = class)) + geom_bar()library(ggplot2) d <- subset(mpg, manufacturer == "ford") # ggplot2 defaults ggplot(d, aes(x = model)) + geom_bar() ggplot(d, aes(x = model, fill = class)) + geom_bar() # Use sgplot defaults use_sgplot() ggplot(d, aes(x = model)) + geom_bar() ggplot(d, aes(x = model, fill = class, colour = class)) + geom_bar() # Use sgplot defaults and Social Security Scotland colour palettes use_sgplot(palette_type = "sss") ggplot(d, aes(x = model)) + geom_bar() ggplot(d, aes(x = model, fill = class, colour = class)) + geom_bar()