Skip to content

Commit

Permalink
Merge pull request #56 from OxfordIHTM/dev
Browse files Browse the repository at this point in the history
update documentation
  • Loading branch information
ernestguevarra authored Mar 13, 2024
2 parents da204b1 + f4209c1 commit 946d5ec
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 536 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.RData
.Ruserdata
docs
inst/doc
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Imports:
withr
Suggests:
covr,
knitr,
rmarkdown,
sf,
spelling,
testthat (>= 3.0.0)
Expand All @@ -31,3 +33,4 @@ Roxygen: list(markdown = TRUE)
URL: https://oxford-ihtm.io/oxthema/,https://github.com/OxfordIHTM/oxthema
BugReports: https://github.com/OxfordIHTM/oxthema/issues
Config/testthat/edition: 3
VignetteBuilder: knitr
4 changes: 2 additions & 2 deletions R/oxford_palettes.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @examples
#' oxford_theme_palettes()
#'
#' @rdname oxford_theme
#' @rdname oxford_palette
#' @export
#'
oxford_theme_palettes <- function() {
Expand Down Expand Up @@ -34,7 +34,7 @@ oxford_theme_palettes <- function() {
#' @examples
#' oxford_brewer_palettes()
#'
#' @rdname oxford_brewer_palette
#' @rdname oxford_palette
#' @export
#'
oxford_brewer_palettes <- function() {
Expand Down
2 changes: 1 addition & 1 deletion R/oxford_theme.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#'
#' A generic/base [ggplot2] theme for the oxfordtheme package
#' A generic/base [ggplot2] theme for the oxthema package
#'
#' This generic/base [ggplot2] theme is the template from which all other
#' themes in the [oxthema] package is built on. This theme is inspired by
Expand Down
228 changes: 4 additions & 224 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -53,234 +53,14 @@ install.packages(

## Usage

### Oxford colours
The following vignettes provide details on how to make full use of the `oxthema` package:

Based on the [University of Oxford](https://ox.ac.uk)'s [visual identity guidelines](https://communications.web.ox.ac.uk/communications-resources/visual-identity/identity-guidelines), the following colours are available from this package:
* [Oxford colours](https://oxford-ihtm.io/oxthema/articles/oxford-colours.html)

```{r oxford-colours, echo = FALSE}
oxford_colours |>
knitr::kable()
```

```{r oxford-colours-graphic, echo = FALSE, fig.height = 1, fig.align = "center"}
structure(get_oxford_colours() |> (\(x) x[x != ""])(), class = "palette", name = "Oxford Colours")
```

You can access either the name, RGB, CMYK, hex code, and/or Pantone values of each Oxford colour through the `get_oxford_colours()` function as follows:

```{r get-colours}
## Get hex code for Oxford blue
get_oxford_colours(pattern = "Oxford blue")
## Get hex code for all colours with "blue" in their name (show name in output)
get_oxford_colours(pattern = "blue", named = TRUE)
```

The `get_oxford_colours()` function can thus be used to create your own bespoke combination of colours from the Oxford colours palette and create your own theme (see next section for University of Oxford officially recommended themes using the Oxford colours).

### Oxford palettes

Based on the [University of Oxford](https://ox.ac.uk)'s [visual identity guidelines](https://communications.web.ox.ac.uk/communications-resources/visual-identity/identity-guidelines) and the carefully curated colour groups of the official University [theme packs](https://communications.web.ox.ac.uk/communications-resources/visual-identity/identity-guidelines/theme-packs), the following palettes are available from this package:

#### Heritage

```{r oxford-palettes-heritage-code}
oxford_theme_palettes()$heritage
```

```{r oxford-palettes-heritage-show, echo = FALSE, fig.height = 1, fig.align = "center"}
structure(oxford_theme_palettes()$heritage, class = "palette", name = "heritage")
```

#### Contemporary

```{r oxford-palettes-contemporary-code}
oxford_theme_palettes()$contemporary
```

```{r oxford-palettes-contemporary-show, echo = FALSE, fig.height = 1, fig.align = "center"}
structure(oxford_theme_palettes()$contemporary, class = "palette", name = "contemporary")
```

#### Celebratory

```{r oxford-palettes-celebratory-code}
oxford_theme_palettes()$celebratory
```

```{r oxford-palettes-celebratory-show, echo = FALSE, fig.height = 1, fig.align = "center"}
structure(oxford_theme_palettes()$celebratory, class = "palette", name = "celebratory")
```

#### Corporate

```{r oxford-palettes-corporate-code}
oxford_theme_palettes()$corporate
```

```{r oxford-palettes-corporate-show, echo = FALSE, fig.height = 1, fig.align = "center"}
structure(oxford_theme_palettes()$corporate, class = "palette", name = "corporate")
```

#### Innovative

```{r oxford-palettes-innovative-code}
oxford_theme_palettes()$innovative
```

```{r oxford-palettes-innovative-show, echo = FALSE, fig.height = 1, fig.align = "center"}
structure(oxford_theme_palettes()$innovative, class = "palette", name = "innovative")
```

### Oxford theme palettes for use in plotting

The University of Oxford recommended theme palettes can be used for plotting. Below is code examples of how this can be done both with base R plotting function and with `ggplot2`.

#### Bar plots in base R and using `ggplot`

```{r mtcars-barplot, fig.show = "hold", fig.height = 8, out.width = "50%"}
## Barplot of cyl and vs of mtcars dataset using heritage Oxford theme
### Base R
table(mtcars$cyl, mtcars$vs) |>
barplot(
names.arg = c("v-shaped", "straight"),
main = "Engine shape by number of cylinders",
ylab = "n",
legend.text = TRUE,
col = oxford_theme_palettes()$heritage,
args.legend = list(
x = "topright",
inset = 0.002,
title = "Cylinders",
bty = "n"
)
)
### ggplot2
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 = oxford_theme_palettes()$heritage) +
labs(
title = "This title is in Oxford Blue",
subtitle = "This subtitle is in Oxford ash grey",
x = "Engine shape",
y = "Counts"
) +
theme_oxford()
```

#### Scatter plots in base R and using `ggplot`
* [Oxford palettes](https://oxford-ihtm.io/oxthema/articles/oxford-palettes.html)

```{r mtcars-scatterplot, fig.show = "hold", fig.height = 8, out.width = "50%"}
## Scatterplot of mpg and disp of mtcars dataset using celebratory Oxford theme
* [Oxford theme](https://oxford-ihtm.io/oxthema/articles/oxford-theme.html)

### Base R
plot(
x = mtcars$mpg,
y = mtcars$disp,
pch = 19, cex = 1.75,
col = ifelse(
mtcars$cyl == 4, oxford_theme_palettes()$celebratory[1],
ifelse(
mtcars$cyl == 6, oxford_theme_palettes()$celebratory[2],
oxford_theme_palettes()$celebratory[3]
)
),
main = "mpg by disp grouped by cyl",
xlab = "mpg", ylab = "disp",
frame.plot = FALSE
)
legend(
x = "topright", inset = 0.02,
title = "Cylinders",
legend = c("4", "6", "8"),
pch = 19, pt.cex = 1.5, bty = "n",
col = oxford_theme_palettes()$celebratory[1:3]
)
### ggplot2
ggplot(data = mtcars, mapping = aes(x = mpg, y = disp, colour = factor(cyl))) +
geom_point(size = 5) +
scale_colour_manual(
name = "Cylinders",
values = oxford_theme_palettes()$celebratory
) +
labs(
title = "This title is in Oxford Blue",
subtitle = "This subtitle is in Oxford Ash Grey"
) +
theme_oxford()
```

#### Plotting maps using Oxford palettes

```{r oxford-palette-sequential, fig.show = "hold", out.width = "50%", fig.height = 8}
## Plot acute malnutrition using Oxford sequential palette
### Yellow-Orange-Brown
ggplot(data = nut_survey_map) +
geom_sf(mapping = aes(fill = muac_mam)) +
scale_fill_gradientn(
name = "",
colours = create_palette_sequential(n = 9, name = "ylorbr")
) +
labs(
title = "Prevalence of moderate child wasting",
subtitle = "Sequential Yellow-Orange-Brown Colour Palette"
) +
theme_oxford()
### Yellow-Green-Blue
ggplot(data = nut_survey_map) +
geom_sf(mapping = aes(fill = muac_sam)) +
scale_fill_gradientn(
name = "",
colours = create_palette_sequential(n = 9, name = "ylgnbu")
) +
labs(
title = "Prevalence of severe child wasting",
subtitle = "Sequential Yellow-Green-Blue Colour Palette"
) +
theme_oxford()
```


```{r oxford-palette-divergent, fig.show = "hold", out.width = "50%", fig.height = 8}
## Plot period prevalence of fever and diarrhoea using Oxford divergent palette
### Pink-Yellow-Green
ggplot(data = nut_survey_map) +
geom_sf(mapping = aes(fill = fev)) +
scale_fill_gradientn(
name = "",
colours = create_palette_divergent(n = 11, name = "piylgn")
) +
labs(
title = "Period prevalence of childhood fever",
subtitle = "Divergent Pink-Yellow-Green Colour Palette"
) +
theme_oxford()
### Purple-Green
ggplot(data = nut_survey_map) +
geom_sf(mapping = aes(fill = dia)) +
scale_fill_gradientn(
name = "",
colours = create_palette_divergent(n = 11, name = "prgn")
) +
labs(
title = "Period prevalence of childhood diarrhoea",
subtitle = "Divergent Purple-Green Colour Palette"
) +
theme_oxford()
```

## Authors

Expand Down
Loading

0 comments on commit 946d5ec

Please sign in to comment.