Skip to content
 
 

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

R-CMD-check

ggONS

This R package contains:

  • scale and theme functions for use with {ggplot2};
  • template for revealjs Quarto presentations;

Installation

This package is not currently on CRAN, so cannot be installed directly with install.packages(). Instead, use pak to install. Start by installing pak:

install.packages("pak")

Method 1: Directly from GitHub

Then install ggONS from GitHub:

pak::pkg_install("ONSdigital/ggONS")

Method 2: Local installation

Alternatively, go to github.com/ONSdigital/ggONS, and click on the green Code button to download a zip file of the package. This will download a file called ggONS-main.zip. Unzip the file.

Then use pak to install locally:

pak::local_install("C:/Users/username/Downloads/ggONS-main/ggONS-main")

Make sure the file path is correct, and points to the unzipped folder.

Examples

Load 'ggplot2' and 'ggONS':

library(ggplot2)
library(ggONS)

Single colour

Use ocean_blue if only requiring one colour:

ggplot(
  data = mpg,
  mapping = aes(y = reorder(class, class, function(x) length(x)))
) +
  geom_bar(fill = ocean_blue) +
  labs(x = "Number of vehicles") +
  theme_ONS() 

Multiple colours

library(gapminder)
gapminder |> 
  dplyr::group_by(year, continent) |> 
  dplyr::summarise(meanLifeExp = mean(lifeExp)) |> 
  dplyr::ungroup() |> 
  ggplot(
    mapping = aes(x = year, y = meanLifeExp, colour = continent)
  ) +
  geom_line() +
  # Use colour scale with categorical palette
  scale_colour_ONS_d() +
  # Use tag instead of `y` for horizontal orientation
  labs(x = NULL, tag = "Average life expectancy") +
  theme_ONS() 

About

R package for ONS ggplot2 themes and scales.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Used by

Contributors

Languages