| Title: | NSW Department of Education branding for figures and tables |
|---|---|
| Description: | doestyle is an R package containing functions to help produce brand-compliant figures for NSW Department of Education publications. |
| Authors: | Samuel Gardiner [aut, cre] (ORCID: <https://orcid.org/0000-0002-6752-6969>), Matthew Finkbeiner [aut] (ORCID: <https://orcid.org/0000-0003-0373-8150>), Jonathan McGuire [aut], United States Web Design System [cph] (Author of included Public Sans font face), Dan Williams [cph] (Author of included Public Sans font face), Pablo Impallari [cph] (Author of included Public Sans font face), Rodrigo Fuenzalida [cph] (Author of included Public Sans font face) |
| Maintainer: | Samuel Gardiner <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.4.0 |
| Built: | 2026-05-31 11:47:26 UTC |
| Source: | https://github.com/nsw-education/doestyle |
showtext and check for presence of Public Sans font familytheme_doe() uses showtext to allow R graphics devices to render the
Public Sans font family. Use check_font_families() to check that Public
Sans is available and to activate showtext. If Public Sans is not installed
on the system or user font search paths, doestyle's embedded copy of the
files will be used.
check_font_families()check_font_families()
check_font_families() does not have a return value and is called
for its side effects.
showtext::showtext_auto() and Public Sans.
doestyle
A dataset containing names, hex and RGB values, and other identifiers for
each colour provided in doestyle. Its content can be visualised with
show_colours() or further manipulated.
colourdatacolourdata
An object of class tbl_df (inherits from tbl, data.frame) with 51 rows and 13 columns.
Department of Education Brand guidelines
Compute contrast ratios between pairs of colours, using the WCAG 2.1 formula.
contrast_ratio(colour1, colour2)contrast_ratio(colour1, colour2)
colour1, colour2
|
Character vectors of hexadecimal colour values. |
Contrast ratio is defined
as where and are the
relative luminances
of the lighter and darker colours being compared.
Contrast ratios range from 1 (no colour contrast) to 21 (maximum contrast). To meet WCAG 2.1 minimum (AA) criteria for accessibility, the contrast ratios between adjacent colours must be:
For text, at least 4.5
For large text (18pt or larger, or 14pt bold), at least 3
For non-text plot elements (e.g. patterns, lines, points, borders etc.), at least 3
To meet WCAG 2.1 enhanced (AAA) contrast requirements, generally a ratio above 7 is required.
See WCAG 2.1 success criteria 1.4.3 Contrast (Minimum), 1.4.6 Contrast (Enhanced) and 1.4.11 Non-text Contrast.
contrast_ratio() returns a numeric vector of contrast ratios, of
the same length as colour1 and colour2.
backgrounds <- doe_cols("white", "black", "blue-01", "grey-04", "black") foregrounds <- doe_cols("black", "white", "blue-03", "grey-03", "black") contrast_ratio(colour1 = backgrounds, colour2 = foregrounds)backgrounds <- doe_cols("white", "black", "blue-01", "grey-04", "black") foregrounds <- doe_cols("black", "white", "blue-03", "grey-03", "black") contrast_ratio(colour1 = backgrounds, colour2 = foregrounds)
doestyle
A list of palettes, organised by type.
doe_palettesdoe_palettes
An object of class palettes_palette (inherits from vctrs_list_of, vctrs_vctr, list) of length 6.
Qualitative: designed to show differences between nominal classes
Sequential: designed to show differences in ordered data that progress in value from low to high (or vice versa)
Diverging: designed to show differences in ordered data that progress away from a central value to extremes at either end of a scale
Palettes can be accessed by their type and name.
# Examine one palette at a time doe_palettes$default doe_palettes$seq.blues # List all palettes and their colours print(doe_palettes) # If you've loaded `palettes`, visualise the available palettes library(palettes) plot(doe_palettes)# Examine one palette at a time doe_palettes$default doe_palettes$seq.blues # List all palettes and their colours print(doe_palettes) # If you've loaded `palettes`, visualise the available palettes library(palettes) plot(doe_palettes)
Add the lower portion of an errorbar to a ggplot plot. This allows the halves of the errorbars to be different colours.
geom_downerrorbar( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_downerrorbar( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other parameters passed to |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
library(doestyle) library(ggplot2) df <- data.frame( observation = c("A", "B", "C"), lower = c(1, 2, 3), estimate = c(2, 4, 4), upper = c(3, 6, 5) ) ggplot(df, aes(x = observation, y = estimate, ymin = lower, ymax = upper)) + geom_col() + geom_uperrorbar(width = 1/10) + geom_downerrorbar(width = 1/10, colour = "white")library(doestyle) library(ggplot2) df <- data.frame( observation = c("A", "B", "C"), lower = c(1, 2, 3), estimate = c(2, 4, 4), upper = c(3, 6, 5) ) ggplot(df, aes(x = observation, y = estimate, ymin = lower, ymax = upper)) + geom_col() + geom_uperrorbar(width = 1/10) + geom_downerrorbar(width = 1/10, colour = "white")
Add the upper portion of an errorbar to a ggplot plot. This allows the halves of the errorbars to be different colours.
geom_uperrorbar( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_uperrorbar( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other parameters passed to |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
library(doestyle) library(ggplot2) df <- data.frame( observation = c("A", "B", "C"), lower = c(1, 2, 3), estimate = c(2, 4, 4), upper = c(3, 6, 5) ) ggplot(df, aes(x = observation, y = estimate, ymin = lower, ymax = upper)) + geom_col() + geom_uperrorbar(width = 1/10) + geom_downerrorbar(width = 1/10, colour = "white")library(doestyle) library(ggplot2) df <- data.frame( observation = c("A", "B", "C"), lower = c(1, 2, 3), estimate = c(2, 4, 4), upper = c(3, 6, 5) ) ggplot(df, aes(x = observation, y = estimate, ymin = lower, ymax = upper)) + geom_col() + geom_uperrorbar(width = 1/10) + geom_downerrorbar(width = 1/10, colour = "white")
Get brand colours by name
get_colours(...) doe_colours(...) doe_cols(...)get_colours(...) doe_colours(...) doe_cols(...)
... |
Colour name(s). May be supplied as a character vector or as individual arguments. |
get_colours() will only return hex values for valid NSW and
Department of Education colour names. To list available colours, use
list_doestyle_colours(). To plot available colours, use show_colours().
get_colours() returns a character vector containing the hex values
for each requested brand colour. If the input contained named arguments,
their names will be used for the outputs.
get_colours("blue-01", "red-02", "blue-04") get_colours(c("red-01", "red-02", "red-03", "red-04"))get_colours("blue-01", "red-02", "blue-04") get_colours(c("red-01", "red-02", "red-03", "red-04"))
List valid NSW or DoE colours and their hex values
list_doestyle_colours()list_doestyle_colours()
A tibble containing the names of valid colours and their hex values.
list_doestyle_colours() list_doestyle_colours() |> print(n = 50)list_doestyle_colours() list_doestyle_colours() |> print(n = 50)
The master dataset contains comprehensive information for all government schools in NSW. Data items include school locations, latitude and longitude coordinates, school type, student enrolment numbers, electorate information, contact details and more. This dataset is publicly available through the Data NSW website.
public_schoolspublic_schools
An object of class spec_tbl_df (inherits from tbl_df, tbl, data.frame) with 2219 rows and 45 columns.
https://data.nsw.gov.au/data/dataset/nsw-education-nsw-public-schools-master-dataset
Compute the relative luminance of sRGB colour(s). See WCAG 2.1 definition: relative luminance.
relative_luminance(hex_values)relative_luminance(hex_values)
hex_values |
A character vector of hex value(s). |
relative_luminance() returns a numeric vector of luminance values.
relative_luminance(c("#ffffff", "#000000", "#002664", "#d7153a")) relative_luminance(doe_cols("white", "black", "blue-01", "red-02"))relative_luminance(c("#ffffff", "#000000", "#002664", "#d7153a")) relative_luminance(doe_cols("white", "black", "blue-01", "red-02"))
Apply a DoE palette to the colour aesthetic
scale_colour_doe( palette = doe_palettes$default, discrete = TRUE, direction = 1, ... )scale_colour_doe( palette = doe_palettes$default, discrete = TRUE, direction = 1, ... )
palette |
An object of class
|
discrete |
Logical indicating whether the desired scale should be
discrete. The default is |
direction |
Sets the order of colours in the scale. If 1, the default, colours are ordered from first to last as they appear in the palette. If -1, the order of colours is reversed. |
... |
Additional arguments passed to |
A scale function that can be added to a ggplot2 plot.
doe_palettes for the palettes available in doestyle.
library(dplyr) library(ggplot2) library(doestyle) # Plot growth in primary and secondary schools over time public_schools |> filter(Level_of_schooling %in% c("Primary School", "Secondary School")) |> arrange(Date_1st_teacher) |> mutate( count = 1, cumulative_schools = cumsum(count), .by = Level_of_schooling) |> ggplot(aes(x = Date_1st_teacher, y = cumulative_schools, colour = Level_of_schooling)) + geom_step() + # Add a default DoE colour scale scale_colour_doe()library(dplyr) library(ggplot2) library(doestyle) # Plot growth in primary and secondary schools over time public_schools |> filter(Level_of_schooling %in% c("Primary School", "Secondary School")) |> arrange(Date_1st_teacher) |> mutate( count = 1, cumulative_schools = cumsum(count), .by = Level_of_schooling) |> ggplot(aes(x = Date_1st_teacher, y = cumulative_schools, colour = Level_of_schooling)) + geom_step() + # Add a default DoE colour scale scale_colour_doe()
Apply a DoE palette to the fill aesthetic
scale_fill_doe( palette = doe_palettes$default, discrete = TRUE, direction = 1, ... )scale_fill_doe( palette = doe_palettes$default, discrete = TRUE, direction = 1, ... )
palette |
An object of class
|
discrete |
Logical indicating whether the desired scale should be
discrete. The default is |
direction |
Sets the order of colours in the scale. If 1, the default, colours are ordered from first to last as they appear in the palette. If -1, the order of colours is reversed. |
... |
Additional arguments passed to |
A scale function that can be added to a ggplot2 plot.
doe_palettes for the palettes available in doestyle.
library(doestyle) library(dplyr) library(ggplot2) public_schools |> filter(grepl("Connected Communities", Principal_network)) |> ggplot(aes(x = Principal_network, fill = Level_of_schooling)) + geom_bar(colour = "black", position = position_dodge(preserve = "single")) + theme(legend.position = "bottom") + labs(y = "Schools") + # Add a default department scale to the `fill` aesthetic. scale_fill_doe()library(doestyle) library(dplyr) library(ggplot2) public_schools |> filter(grepl("Connected Communities", Principal_network)) |> ggplot(aes(x = Principal_network, fill = Level_of_schooling)) + geom_bar(colour = "black", position = position_dodge(preserve = "single")) + theme(legend.position = "bottom") + labs(y = "Schools") + # Add a default department scale to the `fill` aesthetic. scale_fill_doe()
Secondary colours are on-brand colours that can be used for pattern fills or
other visual elements that need contrast against an on-brand fill colour.
Each NSW Design System colour has a corresponding secondary colour available
via secondary_colours().
secondary_colours(...)secondary_colours(...)
... |
Colour name(s). May be supplied as a character vector or as individual arguments. |
secondary_colours() returns the hex value of an appropriate
secondary colour for each on-brand colour name supplied in its arguments.
secondary_colours("red-02", "blue-01", "blue-04")secondary_colours("red-02", "blue-01", "blue-04")
doestyle coloursshow_colours() produces a plot that shows and names the colours available
in doestyle.
show_colours(swatches = c("brand", "primary", "nsw", "all"), linewidth = 1)show_colours(swatches = c("brand", "primary", "nsw", "all"), linewidth = 1)
swatches |
The name of a set of colours to display. " |
linewidth |
The thickness of each swatch's coloured border. |
show_colours() returns a ggplot2 gg object, which can be
further manipulated with user-specified themes etc.
show_colours()show_colours()
Text colours are designed for plotting text over an on-brand fill colour.
Each NSW Design System colour has a corresponding text colour available via
text_colours().
text_colours(...)text_colours(...)
... |
Colour name(s). May be supplied as a character vector or as individual arguments. |
secondary_colours() returns the hex value of an appropriate text
colour for each on-brand colour name supplied in its arguments.
text_colours("red-02", "blue-01", "blue-04")text_colours("red-02", "blue-01", "blue-04")
Apply a minimalist DoE theme. By default, sets the font family to Public Sans
and enables showtext::showtext_auto() to allow easy font display in plots.
theme_doe(base_size = 16, base_family = "Public Sans", ...)theme_doe(base_size = 16, base_family = "Public Sans", ...)
base_size |
Base font size, given in pts. |
base_family |
Base font family. Defaults to the NSW Government on-brand font family, Public Sans. |
... |
Other parameters passed to |
library(doestyle) library(ggplot2) public_schools |> ggplot(aes(y = Operational_directorate)) + geom_bar() + # Apply theme_doe(): minimal decoration and Public Sans typeface theme_doe()library(doestyle) library(ggplot2) public_schools |> ggplot(aes(y = Operational_directorate)) + geom_bar() + # Apply theme_doe(): minimal decoration and Public Sans typeface theme_doe()
Apply a DoE brand-compliant theme to a flextable object.
theme_doe_flextable(x) apply_DoE_zebra_format(x)theme_doe_flextable(x) apply_DoE_zebra_format(x)
x |
a flextable object |
head(mtcars) |> flextable::flextable() |> theme_doe_flextable()head(mtcars) |> flextable::flextable() |> theme_doe_flextable()