Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
^pkgdown$
^doc$
^Meta$
^cran-comments\.md$
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Package: sgplot
Title: Graphic Styles and Colours for Scottish Government Plots
Version: 0.3.0.9000
Version: 0.4.0
Authors@R: c(
person("Scottish Government", , , "statistics.enquiries@gov.scot", role = c("cph", "fnd")),
person("Alice", "Hannah", , "alice.hannah@gov.scot", role = c("aut", "cre"))
)
Description: Standard ggplot theme and colour palettes for use in Scottish
Government.
Description: A 'ggplot2' theme and colour palettes to create accessible
data visualisations in the Scottish Government.
License: MIT + file LICENSE
URL: https://github.com/ScotGovAnalysis/sgplot,
https://ScotGovAnalysis.github.io/sgplot
URL: https://github.com/ScotGovAnalysis/sgplot/,
https://ScotGovAnalysis.github.io/sgplot/
BugReports: https://github.com/ScotGovAnalysis/sgplot/issues
Depends:
R (>= 2.10)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2023
YEAR: 2025
COPYRIGHT HOLDER: Crown Copyright (Scottish Government)
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2023 Crown Copyright (Scottish Government)
Copyright (c) 2025 Crown Copyright (Scottish Government)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
43 changes: 21 additions & 22 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
# sgplot (development version)
# sgplot 0.4.0

* New functionality to set default colour palettes in `use_sgplot()` (#34).
Previously, users were only able to control the default colour in charts
with a single colour (by providing a `default_colour`) and not for charts
where `colour` or `fill` aesthetics were used. Now, the `palette_type` argument
can be used to set the default palette type. For example, Social Security
Scotland users can use `use_sgplot(palette_type = "sss")`. The "sg" palettes
are used by default.
* `use_sgplot()` gains a `palette_type` argument to set default palette type
for geoms. The default value is "sg" to use Scottish Government colour palettes.
To use the Social Security Scotland palette type, for example, use:
`use_sgplot(palette_type = "sss")` (#34).

* The `default_colour` argument of `use_sgplot()` has been deprecated in favour
of the `palette_type` argument (#34).
* The `default_colour` argument of `use_sgplot()` is deprecated in favour of the
`palette_type` argument (#34).

# sgplot 0.3.0

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

* Fix bug in `use_sgplot()` when passing arguments to `theme_sg()`
* Fix bug in `use_sgplot()` when passing arguments to `theme_sg()`.

# sgplot 0.2.2

* Fix links to contributing guidance in vignettes
* Fix links to contributing guidance in vignettes.

* Update required `roxygen` version
* Update required `roxygen` version.

# sgplot 0.2.1

* Fix issue where `scale_` functions didn't work without the package being loaded (#26)
* Fix issue where `scale_` functions didn't work without the package being
loaded (#26).

* Add [examples of using non-default colour palettes](https://ScotGovAnalysis.github.io/sgplot/articles/cookbook.html#using-different-colour-palettes) (#24)
* Add [examples of using non-default colour palettes](https://ScotGovAnalysis.github.io/sgplot/articles/cookbook.html#using-different-colour-palettes) (#24).

* Add link to `theme_sg()` in `use_sgplot()` help file
* Add link to `theme_sg()` in `use_sgplot()` help file.

# sgplot 0.2.0

* Add [Scottish Government Design System colour palettes](https://designsystem.gov.scot/guidance/charts/data-visualisation-colour-palettes)
* Add [Scottish Government Design System colour palettes](https://designsystem.gov.scot/guidance/charts/data-visualisation-colour-palettes).

* Reduce `base_line_size` in `theme_sg()`
* Reduce `base_line_size` in `theme_sg()`.

* Remove default dark blue outline from `geom_col` and `geom_bar` when using `use_sgplot()`.

# sgplot 0.1.0

* First package release
* First package release.

* Add functions to create accessible plots using `ggplot2`
* Add functions to create accessible plots using `ggplot2`.

* Add pkgdown site (https://ScotGovAnalysis.github.io/sgplot) including [cookbook](https://ScotGovAnalysis.github.io/sgplot/articles/cookbook.html)
* Add pkgdown site (https://ScotGovAnalysis.github.io/sgplot) including [cookbook](https://ScotGovAnalysis.github.io/sgplot/articles/cookbook.html).
16 changes: 9 additions & 7 deletions R/colour_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,33 @@

colour_table <- function(pal) {

tibble::enframe(pal) |>
dplyr::mutate(example = "") |>
`%>%` <- dplyr::`%>%`

tibble::enframe(pal) %>%
dplyr::mutate(example = "") %>%
dplyr::mutate(value = factor(
pal,
ordered = TRUE,
levels = unname(pal)
)) |>
gt::gt() |>
)) %>%
gt::gt() %>%
gt::data_color(
columns = .data$value,
target_columns = .data$example,
fn = scales::col_factor(
palette = pal,
domain = NULL
)
) |>
) %>%
gt::cols_width(
name ~ gt::px(110),
value ~ gt::px(100),
example ~ gt::px(150)
) |>
) %>%
gt::cols_align(
align = "left",
columns = dplyr::everything()
) |>
) %>%
gt::cols_label(
name = "Colour name",
value = "Hex code",
Expand Down
2 changes: 2 additions & 0 deletions R/scale_continuous_sg.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#' @param guide A name or function used to create guide. Default is "colourbar".
#' @inheritParams scale_colour_discrete_sg
#'
#' @returns ggplot2 continuous colour/fill scale
#'
#' @examples
#' library(ggplot2)
#'
Expand Down
2 changes: 2 additions & 0 deletions R/scale_discrete_sg.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' reversed.
#' @param ... Additional arguments passed to scale type.
#'
#' @returns ggplot2 discrete colour/fill scale
#'
#' @examples
#' library(ggplot2)
#' library(dplyr)
Expand Down
2 changes: 2 additions & 0 deletions R/theme_sg.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#' @param legend 'right', 'left', 'top', 'bottom', or 'none' to determine the
#' position of the legend. Defaults to 'right'.
#'
#' @returns ggplot2 theme
#'
#' @examples
#' library(ggplot2)
#'
Expand Down
3 changes: 3 additions & 0 deletions R/use_sgplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#' @param default_colour `r lifecycle::badge("deprecated")` Use the
#' `palette_type` argument instead.
#'
#' @returns NULL. Function is used for side effects of setting default ggplot2
#' theme, colour palette and geom aesthetics.
#'
#' @examples
#' library(ggplot2)
#'
Expand Down
25 changes: 11 additions & 14 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,27 @@ sgplot is an R package for creating accessible plots in the Scottish Government.
The package has been developed using the [Government Analysis Function Data Visualisation guidance](https://analysisfunction.civilservice.gov.uk/policy-store/data-visualisation-charts/) and uses accessible colour palettes from the [Scottish Government Design System](https://designsystem.gov.scot/guidance/charts/data-visualisation-colour-palettes).
sgplot should be used in conjunction with these guidance documents.

More information about the package and its functions can be found on the [sgplot website](https://ScotGovAnalysis.github.io/sgplot).
More information about the package and its functions can be found on the [sgplot website](https://ScotGovAnalysis.github.io/sgplot/).
In particular, the [cookbook](https://ScotGovAnalysis.github.io/sgplot/articles/cookbook.html) contains lots of examples.
Slides are also available for an internal [presentation given to statisticians and analysts](https://alice-hannah.github.io/presentations-and-blogs/2023-06-19_sgplot/slides.html).


## Installation

If you are working within the Scottish Government network, you can install sgplot in the same way as with other R packages. The easiest way to do this is by using the [pkginstaller](https://github.com/ScotGovAnalysis/pkginstaller/tree/main) add-in. Further guidance is available on [eRDM](https://erdm.scotland.gov.uk:8443/documents/A42404229/details).
If you are working within the Scottish Government network, you can install sgplot in the same way as with other R packages.

Alternatively, sgplot can be installed directly from GitHub. Note that this method requires the remotes package and may not work from within the Scottish Government network.
Alternatively, install from CRAN:

``` r
remotes::install_github(
"ScotGovAnalysis/sgplot",
upgrade = "never",
build_vignettes = TRUE
)
install.packages("sgplot")
```

Finally, sgplot can also be installed by downloading the [zip of the repository](https://github.com/ScotGovAnalysis/sgplot/archive/main.zip) and running the following code, replacing the section marked `<>` (including the arrows themselves) with the location of the downloaded zip:
Or install the development version from GitHub:

``` r
remotes::install_local(
"<FILEPATH OF ZIPPED FILE>/sgplot-main.zip",
# install.packages("remotes")
remotes::install_github(
"ScotGovAnalysis/sgplot",
upgrade = "never",
build_vignettes = TRUE
)
Expand All @@ -75,7 +72,7 @@ Once installed, sgplot can be loaded using the `library()` function:
library(sgplot)
```

Help files for each function in the package can be found on the [References](https://ScotGovAnalysis.github.io/sgplot/reference) page of the package website. Alternatively, type `?function_name` into the RStudio console. For example:
Help files for each function in the package can be found on the [References](https://ScotGovAnalysis.github.io/sgplot/reference/) page of the package website. Alternatively, type `?function_name` into the RStudio console. For example:

``` r
?theme_sg()
Expand Down Expand Up @@ -135,5 +132,5 @@ Titles, subtitles and captions have been embedded in these example charts for de

Unless stated otherwise, the codebase is released under [the MIT License](LICENSE). This covers both the codebase and any sample code in the documentation.

The documentation is [© Crown copyright](http://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/) and available under the terms
of the [Open Government 3.0](http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/) licence.
The documentation is [© Crown copyright](https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/) and available under the terms
of the [Open Government 3.0](https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/) licence.
37 changes: 12 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ System](https://designsystem.gov.scot/guidance/charts/data-visualisation-colour-
sgplot should be used in conjunction with these guidance documents.

More information about the package and its functions can be found on the
[sgplot website](https://ScotGovAnalysis.github.io/sgplot). In
[sgplot website](https://ScotGovAnalysis.github.io/sgplot/). In
particular, the
[cookbook](https://ScotGovAnalysis.github.io/sgplot/articles/cookbook.html)
contains lots of examples. Slides are also available for an internal
Expand All @@ -34,33 +34,20 @@ analysts](https://alice-hannah.github.io/presentations-and-blogs/2023-06-19_sgpl
## Installation

If you are working within the Scottish Government network, you can
install sgplot in the same way as with other R packages. The easiest way
to do this is by using the
[pkginstaller](https://github.com/ScotGovAnalysis/pkginstaller/tree/main)
add-in. Further guidance is available on
[eRDM](https://erdm.scotland.gov.uk:8443/documents/A42404229/details).
install sgplot in the same way as with other R packages.

Alternatively, sgplot can be installed directly from GitHub. Note that
this method requires the remotes package and may not work from within
the Scottish Government network.
Alternatively, install from CRAN:

``` r
remotes::install_github(
"ScotGovAnalysis/sgplot",
upgrade = "never",
build_vignettes = TRUE
)
install.packages("sgplot")
```

Finally, sgplot can also be installed by downloading the [zip of the
repository](https://github.com/ScotGovAnalysis/sgplot/archive/main.zip)
and running the following code, replacing the section marked `<>`
(including the arrows themselves) with the location of the downloaded
zip:
Or install the development version from GitHub:

``` r
remotes::install_local(
"<FILEPATH OF ZIPPED FILE>/sgplot-main.zip",
# install.packages("remotes")
remotes::install_github(
"ScotGovAnalysis/sgplot",
upgrade = "never",
build_vignettes = TRUE
)
Expand All @@ -75,8 +62,8 @@ library(sgplot)
```

Help files for each function in the package can be found on the
[References](https://ScotGovAnalysis.github.io/sgplot/reference) page of
the package website. Alternatively, type `?function_name` into the
[References](https://ScotGovAnalysis.github.io/sgplot/reference/) page
of the package website. Alternatively, type `?function_name` into the
RStudio console. For example:

``` r
Expand Down Expand Up @@ -151,7 +138,7 @@ License](LICENSE). This covers both the codebase and any sample code in
the documentation.

The documentation is [© Crown
copyright](http://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/)
copyright](https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/)
and available under the terms of the [Open Government
3.0](http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/)
3.0](https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/)
licence.
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
url: https://scotgovanalysis.github.io/sgplot
url: https://ScotGovAnalysis.github.io/sgplot

template:
bootstrap: 5
Expand Down
5 changes: 5 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## R CMD check results

0 errors | 0 warnings | 0 notes

* This is a new release.
Loading