| Title: | Graphic Styles and Colours for Scottish Government Plots |
| Version: | 0.5.0 |
| Description: | A 'ggplot2' theme and colour palettes to create accessible data visualisations in the Scottish Government. |
| License: | MIT + file LICENSE |
| URL: | https://ScotGovAnalysis.github.io/sgplot/, https://github.com/ScotGovAnalysis/sgplot |
| BugReports: | https://github.com/ScotGovAnalysis/sgplot/issues |
| Depends: | R (≥ 2.10) |
| Imports: | cli, ggplot2 (≥ 3.5.0), lifecycle, rlang, scales |
| Suggests: | dplyr, gapminder, glue, gt, knitr, plotly, purrr, rmarkdown, stringr, testthat (≥ 2.1.0), tibble, tidyr |
| Encoding: | UTF-8 |
| LazyData: | true |
| RoxygenNote: | 7.3.3 |
| Config/Needs/website: | rmarkdown |
| NeedsCompilation: | no |
| Packaged: | 2026-01-13 11:26:12 UTC; U449261 |
| Author: | Scottish Government [cph, fnd], Alice Hannah [aut, cre] |
| Maintainer: | Alice Hannah <alice.hannah@gov.scot> |
| Repository: | CRAN |
| Date/Publication: | 2026-01-13 12:00:02 UTC |
sgplot: Graphic Styles and Colours for Scottish Government Plots
Description
A 'ggplot2' theme and colour palettes to create accessible data visualisations in the Scottish Government.
Author(s)
Maintainer: Alice Hannah alice.hannah@gov.scot
Other contributors:
Scottish Government statistics.enquiries@gov.scot [copyright holder, funder]
See Also
Useful links:
Report bugs at https://github.com/ScotGovAnalysis/sgplot/issues
Government Analysis Function colours and palettes
Description
-
af_colour_valuesis a vector containing colour names and their corresponding hex codes. -
af_colour_palettesis a list grouping colours into palettes.
Usage
af_colour_values
af_colour_palettes
Format
An object of class character of length 9.
An object of class list of length 5.
Source
Government Analysis Function Colours Guidance # nolint: line_length_linter.
Available palettes and palette types
Description
Available palettes and palette types
Usage
available_palettes(palette_type, error_call = rlang::caller_env())
available_palette_types()
Arguments
palette_type |
String. |
error_call |
Environment to reference in error messages. |
Value
A character vector of available palettes or palette types.
Examples
available_palette_types()
available_palettes("sg")
Check palettes and palette types
Description
Checks values against those available in
available_palette_types() and available_palettes().
Usage
check_palette(palette_type, palette, error_call = rlang::caller_env())
check_palette_type(palette_type, error_call = rlang::caller_env())
Arguments
palette_type, palette |
String. |
error_call |
Environment to reference in error messages. |
Value
The value being checked is returned invisibly if the check is successful. Otherwise the function will return an error.
Examples
check_palette_type("sg")
check_palette("sg", "main")
Convert millimetres to inches
Description
Convert millimetres to inches
Usage
mm_to_inch(x)
Arguments
x |
Numeric value in millimetres |
Value
A numerical value in inches
Examples
mm_to_inch(100)
Continuous colour/fill scales for Scottish Government plots
Description
Continuous colour/fill scales for Scottish Government plots
Usage
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()
)
Arguments
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 |
Value
ggplot2 continuous colour/fill scale
Examples
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
Description
Discrete colour/fill scales for Scottish Government plots
Usage
scale_colour_discrete_sg(
palette = "main",
palette_type = "sg",
reverse = FALSE,
...
)
scale_fill_discrete_sg(
palette = "main",
palette_type = "sg",
reverse = FALSE,
...
)
Arguments
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. |
Value
ggplot2 discrete colour/fill scale
Examples
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()
Scottish Government colours and palettes
Description
-
sg_colour_valuesis a vector containing colour names and their corresponding hex codes. -
sg_colour_palettesis a list grouping colours into palettes.
Usage
sg_colour_values
sg_colour_palettes
Format
An object of class character of length 11.
An object of class list of length 4.
Source
Scottish Government Design System # nolint: line_length_linter.
Social Security Scotland colours and palettes
Description
-
sss_colour_valuesis a vector containing colour names and their corresponding hex codes. -
sss_colour_palettesis a list grouping colours into palettes.
Usage
sss_colour_values
sss_colour_palettes
Format
An object of class character of length 12.
An object of class list of length 4.
Source
Contact the Social Security Scotland Statistics mailbox # nolint: line_length_linter. with any queries about these colours and palettes.
Scottish Government theme for ggplot2 charts.
Description
ggplot2 theme for Scottish Government plots.
Usage
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")
)
Arguments
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'. |
Value
ggplot2 theme
Examples
library(ggplot2)
p <- ggplot(mpg, aes(x = class)) + geom_bar()
p
p + theme_sg()
Use sgplot defaults.
Description
Set sgplot theme, colour palette and geom aesthetic defaults for ggplot2 charts.
Usage
use_sgplot(
palette_type = "sg",
quietly = FALSE,
...,
default_colour = deprecated()
)
Arguments
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 |
Value
NULL. Function is used for side effects of setting default ggplot2 theme, colour palette and geom aesthetics.
Examples
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()