Skip to content

Theme for use with ggplot2 for creating government style visualisations

License

Notifications You must be signed in to change notification settings

jimr1603/govstyle

 
 

Repository files navigation

Stories in Ready Build Status Build status codecov.io GitHub tag

govstyle

A package for applying a gov.uk style to plots created in the R package ggplot2. This package is in an early stage of development; the intended end point is that it should be fully compliant with the gov.uk style guide.

This package turns plots from this:

Basic ggplot2 plot

to this:

govstyle plot

The best source of docmentation is the vignette.

Installation

To install, the package devtools is required, and can be installed with install.packages('devtools').

govstyle can then be installed using devtools::install_github('ukgovdatascience/govstyle'). Some users may not be able to use the devtools::install_github() commands as a result of network security settings. If this is the case, govstyle can be installed by downloading the zip of the repository and installing the package locally using devtools::install_local(<path to zip file>).

For testing purposes (not general usage), the package visualTest is required. This can be installed with devtools::install_github('mangothecat/visualTest'). For some users devtools::install_local() may also be required.

Functions

  • theme_gov(): Theme to be applied to plots produced in ggplot2 to give a government statistics publication feel.
  • gov_cols: A vector of the gov.uk extended palette.
  • check_pal(): Display the extended gov.uk palette in a pie chart.

Examples

See the vignette for in depth usage examples.

theme_gov

library(ggplot2)
library(dplyr)
#devtools::install_github("ukgovdatascience/govstyle")
library(govstyle)
p <- mtcars %>%
  ggplot +
  aes(
    x = wt,
    y = mpg,
    col = factor(cyl)
    ) +
  geom_point()

p

plot of chunk ggplot_theme_gov

p +
  theme_gov()

plot of chunk ggplot_theme_gov

check_pal

## Show gov.uk colours

check_pal()

plot of chunk check_pal

## Show a subset of gov.uk colours

## Choose n colours:

check_pal(2)

plot of chunk check_pal

check_pal(3)

plot of chunk check_pal

check_pal(4)

plot of chunk check_pal

## Pick a range of colours

check_pal(3:8)

plot of chunk check_pal

check_pal(c(1,10))

plot of chunk check_pal

## Pick colours manually

check_pal(
  x = gov_cols[c("green", "grass_green")]
  )

plot of chunk check_pal

About

Theme for use with ggplot2 for creating government style visualisations

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • R 100.0%