Skip to content

Commit

Permalink
new colour functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestguevarra committed Feb 26, 2024
1 parent 0b612c6 commit cba1f7a
Show file tree
Hide file tree
Showing 21 changed files with 442 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
^\.Rproj\.user$
^LICENSE\.md$
^README\.Rmd$
^\.github$
^codecov\.yml$
^data-raw$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
49 changes: 49 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
50 changes: 50 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
13 changes: 10 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: oxfordtheme
Type: Package
Title: University of Oxford Theme and Theme Components for 'ggplot2'
Title: Oxford Theme and Theme Components
Version: 0.0.0.9000
Authors@R: person(
given = "Ernest",
Expand All @@ -9,10 +9,17 @@ Authors@R: person(
email = "[email protected]",
role = c("aut", "cre")
)
Description: Theme and theme components for 'ggplot2' based on University of
Oxford's visual identity guidelines
Description: Theme and theme components based on University of Oxford's visual
identity guidelines
<https://www.ox.ac.uk/sites/files/oxford/media_wysiwyg/Oxford%20Blue%20LR.pdf>.
License: GPL (>= 3)
Depends:
R (>= 2.10)
Imports:
stringr
Suggests:
covr
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3

4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(cmyk2rgb)
export(oxford_palettes)
importFrom(grDevices,col2rgb)
importFrom(stringr,str_pad)
19 changes: 19 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#'
#' Oxford colours based on University of Oxford's visual identity guidelines
#'
#' @format A data frame with 5 columns and 34 rows:
#'
#' | **Variable** | **Description** |
#' | :--- | :--- |
#' | *name* | Official Oxford colour name |
#' | *rgb* | Three integers for the red, green, blue components of the RGB colour model |
#' | *cmyk* | Four integers for the cyan, magenta, yellow, and black components of the CMYK colour model |
#' | *hex* | Hexadecimal codes for corresponding colour |
#' | *pantone* | Pantone colour name |
#'
#' @examples
#' oxford_colours
#'
#' @source https://communications.web.ox.ac.uk/communications-resources/visual-identity/identity-guidelines/colours
#'
"oxford_colours"
50 changes: 50 additions & 0 deletions R/get_named_colours.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#'
#' Get named Oxford colours vector
#'
#' @param df The `oxford_colours` data.frame.
#' @param type A character vector of colour type. Can be "rgb", "cmyk", "hex",
#' or "pantone". Default is "hex".
#' @param pattern Optional. A character value or vector to use as a search term.
#' Default is NULL.
#'
#' @return A named vector of Oxford colour/s
#'
#' @examples
#' get_oxford_colours()
#' get_oxford_colours(type = "rgb")
#' get_oxford_colours(pattern = "lilac")
#'
#' @export
#'
get_oxford_colours <- function(pattern = NULL,
df = oxford_colours,
type = c("hex", "rgb", "cmyk", "pantone")){
## Get type ----
type <- match.arg(type)

## Determine if there is something specific to search for ----
if (!is.null(pattern)) {
pattern <- paste(pattern, collapse = "|")
## Get colours vector ----
ox_cols <- df[stringr::str_detect(df$name, pattern = pattern,), c("name", type)] |>
(\(x)
{
cols <- x[[type]]
names(cols) <- x[["name"]]
cols
}
)()
} else {
## Get colours vector ----
ox_cols <- df[ , c("name", type)] |>
(\(x)
{
cols <- x[[type]]
names(cols) <- x[["name"]]
cols
}
)()
}

ox_cols
}
18 changes: 18 additions & 0 deletions R/ox_palettes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#'
#' Complete list of Oxford colour palettes
#'
#' @export
#'
oxford_palettes <- list(
blues = c("#4891DC", "#9ECEEB", "#44687D", "#5F9BAF", "#A1C4D0", "#007770", "#7BA296", "#BCD2C3"),
greens = c("#69913B", "#B9CF96", "#CEDBAF", "#AAB300", "#DBDE72", "#E3E597"),
oranges = c("#CF7A30", "#F5CF47", "#F3DE74"),
reds = c("#872434", "#BE0F34", "#EBC4CB"),
grays = c("#A79D96", "#C7C2BC", "#E0DED9"),
heritage = get_oxford_colours(pattern = c("sienna", "peach", "pink", "sage green", "Oxford green", "Oxford blue"))
)





15 changes: 0 additions & 15 deletions R/oxfordtheme-package.R

This file was deleted.

17 changes: 17 additions & 0 deletions R/oxfordtheme.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#'
#' Oxford Theme and Theme Components
#'
#' Theme and theme components for 'ggplot2' based on University of Oxford's
#' visual identity guidelines
#' <https://www.ox.ac.uk/sites/files/oxford/media_wysiwyg/Oxford%20Blue%20LR.pdf>.
#'
#'
#' @md
#' @name oxfordtheme
#' @docType package
#' @author Ernest Guevarra ([email protected])
#' @keywords internal
#' @importFrom stringr str_pad
#' @importFrom grDevices col2rgb
#'
"_PACKAGE"
38 changes: 38 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#'
#' Convert CMYK to RGB
#'
#' @param C An integer value for cyan
#' @param Y An integer value for yellow
#' @param M An integer value for magenta
#' @param K An integer value for key (black)
#'
#' @return A named vector for R, G, and B for RGB
#'
#' @examples
#' cmyk2rgb(100, 80, 0, 60)
#'
#' @export
#'
cmyk2rgb <- function(C, M, Y, K) {
C <- C / 100.0
M <- M / 100.0
Y <- Y / 100.0
K <- K / 100.0

n.c <- (C * (1 - K) + K)
n.m <- (M * (1 - K) + K)
n.y <- (Y * (1 - K) + K)

r.col <- ceiling(255 * (1 - n.c))
g.col <- ceiling(255 * (1 - n.m))
b.col <- ceiling(255 * (1 - n.y))

paste0(
"#",
stringr::str_pad(as.hexmode(r.col), width = 2, side = "left", pad = "0"),
stringr::str_pad(as.hexmode(g.col), width = 2, side = "left", pad = "0"),
stringr::str_pad(as.hexmode(b.col), width = 2, side = "left", pad = "0")
) |>
grDevices::col2rgb() |>
(\(x) c(R = x[1], G = x[2], B = x[3]))()
}
6 changes: 5 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ knitr::opts_chunk$set(
)
```

# oxfordtheme: University of Oxford Theme and Theme Components for 'ggplot2'
# oxfordtheme: Oxford Theme and Theme Components

<!-- badges: start -->
[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/OxfordIHTM/oxfordtheme/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/OxfordIHTM/oxfordtheme/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/OxfordIHTM/oxfordtheme/branch/main/graph/badge.svg)](https://app.codecov.io/gh/OxfordIHTM/oxfordtheme?branch=main)
<!-- badges: end -->

Theme and theme components for 'ggplot2' based on [University of Oxford](https://ox.ac.uk)'s [visual identity guidelines](https://www.ox.ac.uk/sites/files/oxford/media_wysiwyg/Oxford%20Blue%20LR.pdf).
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# oxfordtheme: University of Oxford Theme and Theme Components for ‘ggplot2’
# oxfordtheme: Oxford Theme and Theme Components

<!-- badges: start -->

[![Project Status: WIP – Initial development is in progress, but there
has not yet been a stable, usable release suitable for the
public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/OxfordIHTM/oxfordtheme/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/OxfordIHTM/oxfordtheme/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/OxfordIHTM/oxfordtheme/branch/main/graph/badge.svg)](https://app.codecov.io/gh/OxfordIHTM/oxfordtheme?branch=main)
<!-- badges: end -->

Theme and theme components for ‘ggplot2’ based on [University of
Expand Down
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
comment: false

coverage:
status:
project:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true
Loading

0 comments on commit cba1f7a

Please sign in to comment.