---
title: "NHS Colours, Palettes, and Themes"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{NHS Colours, Palettes, and Themes}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  message = FALSE,
  warning = FALSE,
  error = FALSE,
  collapse = TRUE,
  comment = "#>",
  dev = "ragg_png"
)
```

```{r setup, echo = FALSE}
library(paleta)
library(ggplot2)
```

The NHS (National Health Service) is the publicly funded healthcare system in the United Kingdom. Established in 1948, it provides comprehensive healthcare services that are largely free at the point of use for residents of the UK. The NHS is funded primarily through taxation and is based on the principle of equity, aiming to provide healthcare services based on need rather than the ability to pay.

The NHS covers a wide range of healthcare services, including general practitioner (GP) services, hospital care, mental health services, dental care, and public health initiatives. It operates through a network of hospitals, clinics, GP surgeries, and other healthcare facilities across England, Scotland, Wales, and Northern Ireland.

## NHS colours

### Core colours

The core NHS colours are blue and white:

```{r nhs-blue, echo = FALSE, fig.alt = "NHS primary colour palette", fig.align = "center", fig.height = 1}
structure(nhs_palettes$nhs_primary, class = "palette", name = "NHS Core Colours")
```

This is supplemented by four additional groups of colours. All colours in the palette meet at least an AA accessibility rating, with many achieving the highest AAA rating when used with appropriate contrasts on suitable backgrounds.

### Level 1: Blue tones

Level 1 of the NHS colour palette consists of various shades of blue, emphasizing the association with blue and white. It provides lighter and darker alternatives to the main NHS Blue colour, offering tonal variety while maintaining the core brand identity.

```{r nhs-blue-tones, echo = FALSE, fig.alt = "NHS blue tones palette", fig.align = "center", fig.height = 1}
structure(nhs_palettes$nhs_blue_tones, class = "palette", name = "NHS Blues")
```

### Level 2: Neutrals

These additional colours complement the primary blues in the palette. Black and dark grey are suitable for text depending on the context. Lighter greys can serve as backgrounds, especially online. White serves as the primary neutral base. Proper use of these colours enhances the overall blue and white aesthetic.

```{r nhs-neutrals, echo = FALSE, fig.alt = "NHS neutrals palette", fig.align = "center", fig.height = 1}
structure(nhs_palettes$nhs_neutrals, class = "palette", name = "NHS Neutrals")
```

### Level 3: Support Greens

Green, being closely related to blue in the colour spectrum, complements the blue and white palette. When used moderately and in a supporting role, it maintains the association with blue and white without compromising it. However, if green becomes too dominant, it may hinder people's ability to instantly recognize the NHS as the source of information.

```{r nhs-support-green, echo = FALSE, fig.alt = "NHS support greens palette", fig.align = "center", fig.height = 1}
structure(nhs_palettes$nhs_support_greens, class = "palette", name = "NHS Support Greens")
```

### Level 4: Highlights

Highlights are effective for emphasizing details, adding warmth to the blue theme, and offering accent colours for NHS entities to distinguish themselves. However, excessive use can drastically alter the overall appearance and disassociate the communication from the NHS brand. Therefore, it's advised to use highlights sparingly and avoid large blocks of these colours.

```{r nhs-highlights, echo = FALSE, fig.alt = "NHS highlights palette", fig.align = "center", fig.height = 1}
structure(nhs_palettes$nhs_highlights, class = "palette", name = "NHS Highlights")
```

## NHS sequential brewer palettes

### Blues 

```{r nhs-blues-sequential, echo = FALSE, fig.alt = "NHS sequential blues palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "blues", org = "nhs"), 
  class = "palette", 
  name = "NHS Sequential Blues"
)
```

### Blue to green

```{r nhs-blue-green-sequential, echo = FALSE, fig.alt = "NHS sequential blue to green palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "bugn", org = "nhs"), 
  class = "palette", 
  name = "NHS Sequential Blue to Green"
)
```

### Blue to purple

```{r nhs-blue-purple-sequential, echo = FALSE, fig.alt = "NHS sequential blue to purple palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "bupu", org = "nhs"), 
  class = "palette", 
  name = "NHS Sequential Blue to Purple"
)
```

### Green to blue

```{r nhs-green-blue-sequential, echo = FALSE, fig.alt = "NHS sequential green to blue palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "gnbu", org = "nhs"), 
  class = "palette", 
  name = "NHA Sequential Green to Blue"
)
```

### Greens 

```{r nhs-greens-sequential, echo = FALSE, fig.alt = "NHS sequential greens palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "greens", org = "nhs"), 
  class = "palette", 
  name = "NHS Sequential Greens"
)
```

### Greys

```{r nhs-greys-sequential, echo = FALSE, fig.alt = "NHS sequential greys palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "greys", org = "nhs"), 
  class = "palette", 
  name = "NHS Sequential Greys"
)
```

### Purple to blue

```{r nhs-purple-blue-sequential, echo = FALSE, fig.alt = "NHS sequential purple to blue palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "pubu", org = "nhs"), 
  class = "palette", 
  name = "NHS Sequential Purple to Blue"
)
```

### Purple to blue to green

```{r nhs-purple-blue-green-sequential, echo = FALSE, fig.alt = "NHS sequential purple to blue to green palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "pubugn", org = "nhs"), 
  class = "palette", 
  name = "NHS Sequential Purple to Blue to Green"
)
```

### Purple to red

```{r nhs-purple-red-sequential, echo = FALSE, fig.alt = "NHS sequential purple to red palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "purd", org = "nhs"), 
  class = "palette", 
  name = "NHS Sequential Purple to Red"
)
```

### Red to purple

```{r nhs-red-purple-sequential, echo = FALSE, fig.alt = "NHS sequential red to purple palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "rdpu", org = "nhs"), 
  class = "palette", 
  name = "NHS Sequential Red to Purple"
)
```

### Reds

```{r nhs-reds-sequential, echo = FALSE, fig.alt = "NHS sequential reds palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "reds", org = "nhs"), 
  class = "palette", 
  name = "NHS Sequential Reds"
)
```

### Yellow to green

```{r nhs-yellow-green-sequential, echo = FALSE, fig.alt = "NHS sequential yellow to green palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "ylgn", org = "nhs"), 
  class = "palette", 
  name = "NHS Sequential Yellow to Green"
)
```

### Yellow to green to blue

```{r nhs-yellow-green-blue-sequential, echo = FALSE, fig.alt = "NHS sequential yellow to green to blue palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "ylgnbu", org = "nhs"), 
  class = "palette", 
  name = "NHS Sequential Yellow to Green to Blue"
)
```

### Yellow to orange to red

```{r nhs-yellow-orange-red-sequential, echo = FALSE, fig.alt = "NHS sequential yellow to orange to red palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(n = 9, name = "ylorrd", org = "nhs"), 
  class = "palette", 
  name = "NHS Sequential Yellow to Orange to Red"
)
```

## NHS divergent brewer palettes

### Pink to yellow to green

```{r nhs-pink-yellow-green-sequential, echo = FALSE, fig.alt = "NHS sequential pink to yellow to green palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(
    n = 11, name = "piylgn", org = "nhs", type = "divergent"
  ), 
  class = "palette", 
  name = "NHS Sequential Pink to Yellow to Green"
)
```

### Purple to green

```{r nhs-purple-green-sequential, echo = FALSE, fig.alt = "NHS sequential purple to green palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(
    n = 11, name = "prgn", org = "nhs", type = "divergent"
  ), 
  class = "palette", 
  name = "NHS Sequential Purple to Green"
)
```

### Purple to orange

```{r nhs-purple-orange-sequential, echo = FALSE, fig.alt = "NHS sequential purple to orange palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(
    n = 11, name = "puor", org = "nhs", type = "divergent"
  ), 
  class = "palette", 
  name = "NHS Sequential Purple to Orange"
)
```

### Red to blue

```{r nhs-red-blue-sequential, echo = FALSE, fig.alt = "NHS sequential red to blue palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(
    n = 11, name = "rdbu", org = "nhs", type = "divergent"
  ), 
  class = "palette", 
  name = "NHS Sequential Red to Blue"
)
```

### Red to grey

```{r nhs-red-greye-sequential, echo = FALSE, fig.alt = "NHS sequential red to grey palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(
    n = 11, name = "rdgy", org = "nhs", type = "divergent"
  ), 
  class = "palette", 
  name = "NHA Sequential Red to Grey"
)
```

### Red to yellow to blue

```{r nhs-red-yellow-blue-sequential, echo = FALSE, fig.alt = "NHS sequential red to yellow to blue palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(
    n = 11, name = "rdylbu", org = "nhs", type = "divergent"
  ), 
  class = "palette", 
  name = "NHS Sequential Red to Yellow to Blue"
)
```

### Red to yellow to green

```{r nhs-red-yellow-green-sequential, echo = FALSE, fig.alt = "NHS sequential red to yellow to green palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(
    n = 11, name = "rdylgn", org = "nhs", type = "divergent"
  ), 
  class = "palette", 
  name = "NHS Sequential Red to Yellow to Green"
)
```

## Africa CDC qualitative palettes

### Pastel set 1

```{r nhs-pastel1-qualitative, echo = FALSE, fig.alt = "NHS qualitative pastel set 1 palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(
    n = 8, name = "pastel1", org = "nhs", type = "qualitative"
  ), 
  class = "palette", 
  name = "NHS Qualitative Pastel Set 1"
)
```

### Dark

```{r nhs-dark-qualitative, echo = FALSE, fig.alt = "NHS qualitative dark palette", fig.align = "center", fig.height = 1}
structure(
  paleta_create_brewer(
    n = 5, name = "dark", org = "nhs", type = "qualitative"
  ), 
  class = "palette", 
  name = "NHS Qualitative Dark"
)
```

## NHS `ggplot2` theme

An NHS `ggplot2` theme function called `theme_nhs()` is included in the `paleta` package. Following are examples of how it can be used.

```{r nhs-theme-bar, echo = FALSE, fig.alt = "A bar plot showcasing the NHS ggplot2 theme", fig.align = "center", fig.showtext = TRUE, fig.height = 6, fig.width = 5, fig.retina = 1}
## bar plot using theme_nhs()
ggplot(
  data = mtcars,
  mapping = aes(
  x = factor(vs, levels = c(0, 1), labels = c("v-shaped", "straight")),
  fill = factor(cyl))
) +
  geom_bar() +
  scale_fill_manual(
    name = "Cylinders", 
    values = nhs_palettes$nhs_blues
  ) +
  labs(
    title = "NHS Theme",
    subtitle = "NHS blue tints palette",
    x = "Engine Shape", y = "Counts"
  ) +
  theme_nhs(grid = "Y")
```

```{r nhs-theme-scatter, echo = FALSE, fig.alt = "A scatter plot showcasing the NHS ggplot2 theme", fig.align = "center", fig.showtext = TRUE, fig.height = 6, fig.width = 5, fig.retina = 1}
## scatterplot using theme_nhs()
ggplot(data = mtcars, mapping = aes(x = mpg, y = disp, colour = factor(cyl))) +
  geom_point(size = 3) +
  scale_colour_manual(
    name = "Cylinders", 
    values = nhs_palettes$nhs_support_greens
  ) +
  labs(
    title = "NHS Theme",
    subtitle = "NHS support greens palette",
  ) +
  theme_nhs(grid = "XY")
```
