| Title: | Easy data viz - NSW Government colour & typography design |
|---|---|
| Description: | This package allows NSW Government R users to create data visualisations in keeping with the NSW Design System. This ensures a consistent approach to data visualisations with appropriate colours and fonts. |
| Authors: | Zoe Baldwin [aut, cre] (ORCID: <https://orcid.org/0000-0002-6010-9361>), Carl Suster [aut] (ORCID: <https://orcid.org/0000-0001-7021-9380>), Shaun Nielsen [ctb], Tyson Goddard [ctb] |
| Maintainer: | Zoe Baldwin <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-21 10:09:28 UTC |
| Source: | https://github.com/digitalnsw/nsw-r-visualisations |
This package was inspired by the data viz work of Cara Thompson (https://github.com/cararthompson).
Maintainer: Zoe Baldwin [email protected] (ORCID)
Authors:
Carl Suster [email protected] (ORCID)
Other contributors:
Shaun Nielsen [email protected] [contributor]
Tyson Goddard [email protected] [contributor]
Useful links:
Report bugs at https://github.com/digitalnsw/nsw-r-visualisations/issues
The NSW design system colours work in grids of colour columns and tonal rows.
col_nsw() allows accessing a colour grid like a matrix.
For ggplot colour palettes, you'll normally want pal_nsw() instead.
define_colour_theme() defines a new colour theme that can be used
in any waratah function that accepts a variant parameter.
nsw_colours define_colour_theme(name, parent, colours) col_nsw( hue, tone, variant = getOption("waratah.colour_theme", default = "base"), byrow = FALSE )nsw_colours define_colour_theme(name, parent, colours) col_nsw( hue, tone, variant = getOption("waratah.colour_theme", default = "base"), byrow = FALSE )
name |
name for the new colour theme. |
parent |
name of the parent grid or theme, usually |
colours |
character vector of colour column names. |
hue |
name or index of the hue - see below. |
tone |
name or index of the tone - see below. |
variant |
name of palette variant. Available options are: base, aboriginal, corporate, treasury. |
byrow |
vary |
hue and tone work the same way as matrix indexing with [ in that they
can be used to return single or multiple entries from the grid.
They can be character vectors, integer vectors, or logicals.
Anchor colours used to create the NSW colour palettes can also be used
stand-alone (e.g. nsw_colours$blue_01 is "#002664").
for col_nsw() a named vector of colours,
for define_colour_theme() nothing: this is called for its side effects.
The "base" variant supports:
hue: greys, greens, teals, blues, purples, fucshias, reds, oranges, yellows, browns
tone: dark, normal, light, pale
The "aboriginal" variant supports:
hue: reds, oranges, browns, yellows, greens, blues, purples, greys
tone: dark, normal, light, pale
Colour themes support subsets of the hues from one of the main grids in a specific order. These themes are built in:
"treasury": teals, greys, oranges, greens
"corporate": blues, reds, greys
The default variant can be specified globally with options(waratah.colour_theme).
Unambiguous shortened forms are accepted, e.g. pal_nsw(h = "red", v = "a").
col_nsw(h = "blue", v = "aboriginal") col_nsw(h = c("teal", "orange"), t = 1:2) col_nsw(h = c("teal", "orange"), t = 1:2, byrow = TRUE)col_nsw(h = "blue", v = "aboriginal") col_nsw(h = c("teal", "orange"), t = 1:2) col_nsw(h = c("teal", "orange"), t = 1:2, byrow = TRUE)
Depending on the structure of your data you may wish to combine palettes according to some pattern. These helpers may come in handy.
pal_c() concatenates multiple discrtee palettes.
pal_interleave() interleaves colours from multiple palettes of the same size.
It helps when your data are grouped and you need more flexibility than the colour grid.
pal_stretch() interpolates a palette into a new discrete palette.
It's useful for stretching the 4 tones into 5 or 6, at the expense of straying from
the NSW grid.
col_contrasting() chooses colours based on the given background colours.
It helps when drawing text on top of a mapped (i.e. variable) fill aesthetic
pal_interleave(...) pal_c(...) pal_stretch(pal) col_contrasting(colour, light = "white", dark = "black")pal_interleave(...) pal_c(...) pal_stretch(pal) col_contrasting(colour, light = "white", dark = "black")
... |
two or more vectors of colours. |
pal |
palette object. |
colour |
vector of colours. |
light, dark
|
colours to output when |
for col_contrasting() a vector of colours the same length as colour,
for pal_*() a palette object.
Palettes created using the NSW Design System.
To use the Aboriginal colour grid, specify variant = "aboriginal".
pal_nsw( palette = waiver(), hue = NA, tone = NA, variant = getOption("waratah.colour_theme", default = "base"), direction = 1 ) pal_nsw_manual(colours)pal_nsw( palette = waiver(), hue = NA, tone = NA, variant = getOption("waratah.colour_theme", default = "base"), direction = 1 ) pal_nsw_manual(colours)
palette |
name of a predefined palette: default, brand_default, core. |
hue |
name or index of the hue - see below.
Ignored if |
tone |
name or index of the tone - see below.
Ignored if |
variant |
name of palette variant.
Available options are: base, aboriginal, corporate, treasury.
Ignored unless |
direction |
set to -1 to reverse the order of colours in the palette, or 1 for the original order. |
colours |
vector of colour names corresponding to nsw_colours. |
To use palettes based on the NSW Design System colour grids, either
specify hue and allow the tone to vary, or specify tone to allow the
hue to vary.
The recommendation is to use the first two tonal rows going one colour at a
time from a set of colours; this can be achieved by specifying tone = 1:2.
There are several named palettes which can be specified with palette.
To create custom combinations of named colours from the design system, use
pal_nsw_manual().
A palette object (see palette constructors)
The "base" variant supports:
hue: greys, greens, teals, blues, purples, fucshias, reds, oranges, yellows, browns
tone: dark, normal, light, pale
The "aboriginal" variant supports:
hue: reds, oranges, browns, yellows, greens, blues, purples, greys
tone: dark, normal, light, pale
Colour themes support subsets of the hues from one of the main grids in a specific order. These themes are built in:
"treasury": teals, greys, oranges, greens
"corporate": blues, reds, greys
The default variant can be specified globally with options(waratah.colour_theme).
Unambiguous shortened forms are accepted, e.g. pal_nsw(h = "red", v = "a").
Other palettes:
pal_waratah()
library(scales) pal_nsw() |> show_col() pal_nsw(hue = "blues") |> show_col() pal_nsw(tone = 1:2, variant = "corporate") |> show_col() pal_nsw(tone = "light") |> show_col() pal_nsw(tone = "normal", variant = "aboriginal") |> show_col() pal_nsw_manual(c("blue_02", "red_01", "green_03")) |> show_col() # you can interpolate colours by converting to a continuous scale pal_nsw(hue = "blues") |> as_continuous_pal() |> show_col(labels = FALSE)library(scales) pal_nsw() |> show_col() pal_nsw(hue = "blues") |> show_col() pal_nsw(tone = 1:2, variant = "corporate") |> show_col() pal_nsw(tone = "light") |> show_col() pal_nsw(tone = "normal", variant = "aboriginal") |> show_col() pal_nsw_manual(c("blue_02", "red_01", "green_03")) |> show_col() # you can interpolate colours by converting to a continuous scale pal_nsw(hue = "blues") |> as_continuous_pal() |> show_col(labels = FALSE)
Unlike pal_nsw(), pal_waratah() is not based strictly on the NSW colour
palette grids.
It tries to choose colours that are perceptually distinct, optionally taking
into account colour-blindness when doing so.
pal_waratah( type = c("qual", "seq", "div", "pairs", "triples"), hue = 1, cvd = getOption("waratah.cvd", default = FALSE), variant = getOption("waratah.colour_theme", default = "base"), direction = 1 )pal_waratah( type = c("qual", "seq", "div", "pairs", "triples"), hue = 1, cvd = getOption("waratah.cvd", default = FALSE), variant = getOption("waratah.colour_theme", default = "base"), direction = 1 )
type |
type of palette that should be generated:
|
hue |
main hue, either by name of index.
See |
cvd |
when |
variant |
name of palette variant.
Available options are: base, aboriginal, corporate, treasury.
Ignored unless |
direction |
set to -1 to reverse the order of colours in the palette, or 1 for the original order. |
A palette object (see palette constructors)
Other palettes:
pal_nsw()
library(scales) pal_waratah("qual") |> show_col() pal_waratah("pairs") |> show_col() pal_waratah("seq", hue = "red") |> show_col(labels = FALSE) pal_waratah("div", hue = "yellow", variant = "aboriginal") |> show_col(labels = FALSE)library(scales) pal_waratah("qual") |> show_col() pal_waratah("pairs") |> show_col() pal_waratah("seq", hue = "red") |> show_col(labels = FALSE) pal_waratah("div", hue = "yellow", variant = "aboriginal") |> show_col(labels = FALSE)
If using reactable, this helper constructs a theme.
reactable_theme( colour = "blue_01", text_colour = colour, borderColor = colour, backgroundColor = "white", base_family = "Public Sans", title_family = "Public Sans", base_text_size = 10, stripedColor = NA, ... )reactable_theme( colour = "blue_01", text_colour = colour, borderColor = colour, backgroundColor = "white", base_family = "Public Sans", title_family = "Public Sans", base_text_size = 10, stripedColor = NA, ... )
colour |
starting colour used only to set a common default for other colour parameters. |
text_colour |
colour of all text. |
borderColor |
colour for the horizontal lines between rows. |
backgroundColor |
background colour. |
base_family |
font family for normal text. |
title_family |
font family for title text. |
base_text_size |
base text size in pt. The header size is relative to the base text size. |
stripedColor |
fill colour for alternate rows.
When |
... |
other parameters to pass to |
Colours can be specified as named NSW colours as in nsw_colours.
As normal with HTML elements, you must make sure that the final document
loads the necessary fonts. See vignette("waratah") for instructions.
A reactable theme object
library(reactable) # The default theme head(palmerpenguins::penguins, 10) |> reactable(theme = reactableTheme()) # Adding waratah style head(palmerpenguins::penguins, 10) |> reactable(theme = reactable_theme()) # More customised styling head(palmerpenguins::penguins, 10) |> reactable( theme = reactable_theme( colour = "blue_01", base_family = "Arial", text_colour = "black", backgroundColor = NULL ), striped = TRUE )library(reactable) # The default theme head(palmerpenguins::penguins, 10) |> reactable(theme = reactableTheme()) # Adding waratah style head(palmerpenguins::penguins, 10) |> reactable(theme = reactable_theme()) # More customised styling head(palmerpenguins::penguins, 10) |> reactable( theme = reactable_theme( colour = "blue_01", base_family = "Arial", text_colour = "black", backgroundColor = NULL ), striped = TRUE )
A 'ggplot2' theme compatible with the NSW design system. It sets default colour scales, fonts, and some other styles.
theme_waratah( base_size = 11, base_family = "Public Sans", header_family = "Public Sans", base_line_size = base_size/22, base_rect_size = base_size/22, ink = "black", paper = "white", geom_ink = "blue_01", accent = "blue_02", variant = getOption("waratah.colour_theme", default = "base"), show_grid_lines = TRUE, void = FALSE )theme_waratah( base_size = 11, base_family = "Public Sans", header_family = "Public Sans", base_line_size = base_size/22, base_rect_size = base_size/22, ink = "black", paper = "white", geom_ink = "blue_01", accent = "blue_02", variant = getOption("waratah.colour_theme", default = "base"), show_grid_lines = TRUE, void = FALSE )
base_size |
base font size, given in pts. |
base_family |
base font family |
header_family |
font family for titles and headers. The default, |
base_line_size |
base size for line elements |
base_rect_size |
base size for rect elements |
ink, paper, accent
|
colour for foreground, background, and accented elements respectively. |
geom_ink |
default ink colour used by geoms for points, lines and fills. |
variant |
name of palette variant. Available options are: base, aboriginal, corporate, treasury. |
show_grid_lines |
whether to show grid lines.
If |
void |
whether to hide grid lines and axes.
If |
ggplot theme specification to add to a plot
library(ggplot2) set_theme(theme_waratah()) ggplot(palmerpenguins::penguins) + geom_point(aes( x = bill_length_mm, y = flipper_length_mm, colour = species, size = body_mass_g )) + labs( caption = "Data from {palmerpenguins}", dictionary = c( bill_length_mm = "Bill length (mm)", flipper_length_mm = "Flipper length (mm)", species = "Species", body_mass_g = "Body mass (g)" ) )library(ggplot2) set_theme(theme_waratah()) ggplot(palmerpenguins::penguins) + geom_point(aes( x = bill_length_mm, y = flipper_length_mm, colour = species, size = body_mass_g )) + labs( caption = "Data from {palmerpenguins}", dictionary = c( bill_length_mm = "Bill length (mm)", flipper_length_mm = "Flipper length (mm)", species = "Species", body_mass_g = "Body mass (g)" ) )
CSS code required to add waratah-styled tooltips to interactive graphs created using ggiraph.
tooltip_css( background_colour = "grey_01", text_colour = "off_white", font_family = "\"Public Sans\", Arial, sans", font_size = "11pt" )tooltip_css( background_colour = "grey_01", text_colour = "off_white", font_family = "\"Public Sans\", Arial, sans", font_size = "11pt" )
background_colour |
tooltip background colour |
text_colour |
tooltip text colour |
font_family |
font family for text in tooltips |
font_size |
font size for text in tooltips |
As normal with HTML elements, you must make sure that the final document
loads the necessary fonts. See vignette("waratah") for instructions.
A character vector containing CSS rules
tooltip_css()tooltip_css()