Skip to content

Commit

Permalink
Merge pull request #42 from ScotGovAnalysis/sss-colours
Browse files Browse the repository at this point in the history
Add Social Security Scotland colours
  • Loading branch information
alice-hannah authored Oct 28, 2024
2 parents bbcc8be + 9df2254 commit 9a74fca
Show file tree
Hide file tree
Showing 22 changed files with 230 additions and 122 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# sgplot (development version)

* Add Social Security Scotland colours (`sss_colour_values`) and palettes (`sss_colour_palettes`)

# sgplot 0.2.2

* Fix links to contributing guidance in vignettes
Expand Down
52 changes: 26 additions & 26 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
# nolint start
# nolint: start
#' @title Scottish Government colour names and hex codes
#'
#' @description A vector containing colour names and their corresponding
#' hex code.
#' @description
#' * \code{sg_colour_values} is a vector containing colour names and their corresponding
#' hex codes.
#' * \code{sg_colour_palettes} is a list grouping colours into palettes.
#'
#' @format A character vector
#' @source \href{https://designsystem.gov.scot/guidance/charts/data-visualisation-colour-palettes}{Scottish Government Design System}
# nolint end
#' @md
# nolint: end

"sg_colour_values"

#' @rdname sg_colour_values
"sg_colour_palettes"

# nolint start
#' @title Scottish Government colour palettes
#'
#' @description A list grouping colours into palettes.

#' @title Social Security Scotland colour names and hex codes
#'
#' @format A character list
#' @source \href{https://designsystem.gov.scot/guidance/charts/data-visualisation-colour-palettes}{Scottish Government Design System}
# nolint end
#' @description
#' * \code{sss_colour_values} is a vector containing colour names and their corresponding
#' hex codes.
#' * \code{sss_colour_palettes} is a list grouping colours into palettes.
#' @md

"sg_colour_palettes"
"sss_colour_values"

#' @rdname sss_colour_values
"sss_colour_palettes"


# nolint start
#' @title Analysis Function colour names and hex codes
#'
#' @description A vector containing colour names and their corresponding
#' hex code.
#' @description
#' * \code{af_colour_values} is a vector containing colour names and their corresponding
#' hex codes.
#' * \code{af_colour_palettes} is a list grouping colours into palettes.
#'
#' @format A character vector
#' @source \href{https://analysisfunction.civilservice.gov.uk/policy-store/data-visualisation-colours-in-charts/}{Government Analysis Function Colours Guidance}
#' @md
# nolint end

"af_colour_values"


# nolint start
#' @title Analysis Function colour palettes
#'
#' @description A list grouping colours into palettes.
#'
#' @format A character list
#' @source \href{https://analysisfunction.civilservice.gov.uk/policy-store/data-visualisation-colours-in-charts/}{Government Analysis Function Colours Guidance}
# nolint end

#' @rdname af_colour_values
"af_colour_palettes"
12 changes: 7 additions & 5 deletions R/scale_colour_continuous_sg.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#'
#' @param palette Name of palette to use; e.g. "main", "sequential", "focus".
#' Default value is "sequential".
#' @param palette_type Either "sg" to use Scottish Government palettes, or "af"
#' to use Analysis Function palettes. Defaults to "sg".
#' @param palette_type Either `sg` to use Scottish Government palettes, `sss`
#' to use Social Security Scotland palettes or `af` to use Analysis Function
#' palettes. Defaults to `sg`.
#' @param reverse Boolean value to indicate whether the palette should be
#' reversed.
#' @param na_colour Colour to set for missing values.
Expand All @@ -20,7 +21,7 @@
#' @export

scale_colour_continuous_sg <- function(palette = "sequential",
palette_type = c("sg", "af"),
palette_type = c("sg", "sss", "af"),
reverse = FALSE,
na_colour = "grey50",
guide = "colourbar",
Expand All @@ -30,8 +31,9 @@ scale_colour_continuous_sg <- function(palette = "sequential",

palette_list <- switch(
palette_type,
af = sgplot::af_colour_palettes,
sg = sgplot::sg_colour_palettes
af = sgplot::af_colour_palettes,
sg = sgplot::sg_colour_palettes,
sss = sgplot::sss_colour_palettes
)

# Error if palette doesn't exist
Expand Down
7 changes: 4 additions & 3 deletions R/scale_colour_discrete_sg.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#'
#' @param palette Name of palette to use; e.g. "main", "sequential", "focus."
#' Default value is "main".
#' @param palette_type Either "sg" to use Scottish Government palettes, or "af"
#' to use Analysis Function palettes. Defaults to "sg".
#' @param palette_type Either `sg` to use Scottish Government palettes, `sss`
#' to use Social Security Scotland palettes or `af` to use Analysis Function
#' palettes. Defaults to `sg`.
#' @param reverse Boolean value to indicate whether the palette should be
#' reversed.
#' @param ... Additional arguments passed to scale type.
Expand All @@ -21,7 +22,7 @@
#' @export

scale_colour_discrete_sg <- function(palette = "main",
palette_type = c("sg", "af"),
palette_type = c("sg", "sss", "af"),
reverse = FALSE,
...) {

Expand Down
12 changes: 7 additions & 5 deletions R/scale_fill_continuous_sg.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#'
#' @param palette Name of palette to use; e.g. "main", "sequential", "focus."
#' Default value is "sequential".
#' @param palette_type Either "sg" to use Scottish Government palettes, or "af"
#' to use Analysis Function palettes. Defaults to "sg".
#' @param palette_type Either `sg` to use Scottish Government palettes, `sss`
#' to use Social Security Scotland palettes or `af` to use Analysis Function
#' palettes. Defaults to `sg`.
#' @param reverse Boolean value to indicate whether the palette should be
#' reversed.
#' @param na_colour Colour to set for missing values.
Expand All @@ -20,7 +21,7 @@
#' @export

scale_fill_continuous_sg <- function(palette = "sequential",
palette_type = c("sg", "af"),
palette_type = c("sg", "sss", "af"),
reverse = FALSE,
na_colour = "grey50",
guide = "colourbar",
Expand All @@ -30,8 +31,9 @@ scale_fill_continuous_sg <- function(palette = "sequential",

palette_list <- switch(
palette_type,
af = sgplot::af_colour_palettes,
sg = sgplot::sg_colour_palettes
af = sgplot::af_colour_palettes,
sg = sgplot::sg_colour_palettes,
sss = sgplot::sss_colour_palettes
)

# Error if palette doesn't exist
Expand Down
9 changes: 5 additions & 4 deletions R/scale_fill_discrete_sg.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#' @title Discrete colour fill scales for Scottish Government plots
#'
#' @param palette Name of palette to use; e.g. "main", "sequential", "focus."
#' Default value is "main."
#' @param palette_type Either "sg" to use Scottish Government palettes, or "af"
#' to use Analysis Function palettes. Defaults to "sg".
#' Default value is "main".
#' @param palette_type Either `sg` to use Scottish Government palettes, `sss`
#' to use Social Security Scotland palettes or `af` to use Analysis Function
#' palettes. Defaults to `sg`.
#' @param reverse Boolean value to indicate whether the palette should be
#' reversed.
#' @param ... Additional arguments passed to scale type.
Expand All @@ -20,7 +21,7 @@
#' @export

scale_fill_discrete_sg <- function(palette = "main",
palette_type = c("sg", "af"),
palette_type = c("sg", "sss", "af"),
reverse = FALSE,
...) {

Expand Down
18 changes: 10 additions & 8 deletions R/sg_palette.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
#' Return function to use Scottish Government colour palette
#'
#' @param palette Name of palette from `sg_colour_palettes`
#' @param palette Name of palette to use.
#' @param reverse Boolean value to indicate whether the palette should be
#' reversed
#' reversed.
#' @param colour_names Boolean value to indicate whether colour names should be
#' included
#' @param palette_type Either `sg` to use Scottish Government palettes, or `af`
#' to use Analysis Function palettes. Defaults to `sg`.
#' included.
#' @param palette_type Either `sg` to use Scottish Government palettes, `sss`
#' to use Social Security Scotland palettes or `af` to use Analysis Function
#' palettes. Defaults to `sg`.
#'
#' @noRd

sg_palette <- function(palette = "main",
reverse = FALSE,
colour_names = FALSE,
palette_type = c("sg", "af")) {
palette_type = c("sg", "sss", "af")) {

palette_type <- match.arg(palette_type)

palette_list <- switch(
palette_type,
af = sgplot::af_colour_palettes,
sg = sgplot::sg_colour_palettes
af = sgplot::af_colour_palettes,
sss = sgplot::sss_colour_palettes,
sg = sgplot::sg_colour_palettes
)

# Check valid palette name
Expand Down
3 changes: 2 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ reference:
contents:
- theme_sg

- title: Colours
- title: Colour scales
contents:
- starts_with("scale")

- title: Colour values
contents:
- starts_with("sg_colour")
- starts_with("sss_colour")
- starts_with("af_colour")

- title: Helpers
Expand Down
32 changes: 32 additions & 0 deletions data-raw/sss_colours.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Social Security Scotland (SSS) colours and palettes ----

sss_colour_values <- c(
`navy` = "#201751",
`pink` = "#ff2891",
`purple` = "#461643",
`orange` = "#e5682a",
`dark-green` = "#0b4c0b",
`green` = "#5d9f3c",
`brown` = "#592c20",
`light-pink` = "#ca72a2",
`dark-blue` = "#002d54",
`mid-blue` = "#0065bd",
`light-blue` = "#55a8f2",
`grey` = "#949494"
)

sss_colour_palettes <- list(
`main` = sss_colour_values[c("navy", "pink", "purple", "orange")],
`main-extended` = sss_colour_values[c(
"navy", "pink", "purple",
"orange", "dark-green", "green",
"brown", "light-pink"
)],
`sequential` = sss_colour_values[c("dark-blue", "mid-blue", "light-blue")],
`focus` = sss_colour_values[c("dark-blue", "grey")]
)

usethis::use_data(sss_colour_values, sss_colour_palettes, overwrite = TRUE)


### END OF SCRIPT ###
Binary file added data/sss_colour_palettes.rda
Binary file not shown.
Binary file added data/sss_colour_values.rda
Binary file not shown.
19 changes: 0 additions & 19 deletions man/af_colour_palettes.Rd

This file was deleted.

14 changes: 11 additions & 3 deletions man/af_colour_values.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/scale_colour_continuous_sg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/scale_colour_discrete_sg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/scale_fill_continuous_sg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9a74fca

Please sign in to comment.