An open API service indexing awesome lists of open source software.

https://github.com/nhs-south-central-and-west/scwplot

R package for creating consistent SCW-style ggplot figures.
https://github.com/nhs-south-central-and-west/scwplot

data-visualisation ggplot r rstats

Last synced: 11 months ago
JSON representation

R package for creating consistent SCW-style ggplot figures.

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r setup, include = FALSE}
#| label: setup
#| include: false

knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# scwplot

[![check-standard](https://github.com/NHS-South-Central-and-West/scwplot/actions/workflows/check-standard.yaml/badge.svg)](https://github.com/NHS-South-Central-and-West/scwplot/actions/workflows/check-standard.yaml)
[![codecov](https://codecov.io/gh/NHS-South-Central-and-West/scwplot/branch/main/graph/badge.svg?token=00PF3Y2TDL)](https://codecov.io/gh/NHS-South-Central-and-West/scwplot)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)

The scwplot package provides functions for applying consistent SCW-branded aesthetics to ggplot visualisations in R, as well as additional functionality that produces clean plots and makes plotting in R easier.

## Installation

scwplot is not available on CRAN. In order to install the package, you must do so directly from this GitHub repository with {devtools}, using the code below:

```{r}
#| label: install-scwplot
#| eval: false

# install.packages("pak")
pak::pak("NHS-South-Central-and-West/scwplot")
```

If you haven't already installed devtools, you will also have to run the first line of code in the code chunk.

## Usage

The primary purpose of scwplot is to extend the functionality of ggplot to create consistent SCW-style figures, so usage builds on top of basic [ggplot2](https://ggplot2.tidyverse.org/) functionality.

A simple example of the scwplot usage:

```{r}
#| label: scwplot-basics
#| fig.width: 12
#| fig.height: 8
#| dpi: 300

library(ggplot2)
library(scwplot)

ggplot(mpg, aes(displ, hwy, fill = as.factor(cyl))) +
geom_jitter(
shape = 21, size = 6, stroke = 1,
alpha = .8, width = .5, height = 2.5
) +
labs(
title = "Example {scwplot} Usage with MPG Dataset",
subtitle = glue::glue(
"Plotting the Effect of Engine Displacement on ",
"Highway Miles Per Gallon, Split by Cylinders"
),
caption = "Source: EPA (https://fueleconomy.gov)",
x = "Engine Displacement (in Litres)", y = "Miles per Gallon"
) +
scale_fill_qualitative(palette = "scw") +
theme_scw()
```

The package includes the following functionality:

- Themes - functions for controlling the display of plot theme elements.
- Colour - functions for incorporating the use of colour to display data.
- Images - functions for adding images (i.e., brand images and logos) to plots.
- Format - functions for applying final formatting to a plot and saving it to file.

## Acknowledgements

This package takes a lot of inspiration from the NHS-R community's [NHSRtheme](https://github.com/nhs-r-community/NHSRtheme) package and BBC's [bbplot](https://github.com/bbc/bbplot) package. The code, the structure of the repository, and the approach taken to achieve the package's goals has been influenced by [ggplot2](https://ggplot2.tidyverse.org/) and [ggsci](https://nanx.me/ggsci/).