diff --git a/.Rbuildignore b/.Rbuildignore index 9f58a17..5d821aa 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -2,3 +2,6 @@ ^\.Rproj\.user$ ^LICENSE\.md$ ^README\.Rmd$ +^\.github$ +^codecov\.yml$ +^data-raw$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..74d8c97 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -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 diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..960234c --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -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 diff --git a/DESCRIPTION b/DESCRIPTION index c404e34..7292a52 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", @@ -9,10 +9,17 @@ Authors@R: person( email = "ernest@guevarra.io", 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 . License: GPL (>= 3) +Depends: + R (>= 2.10) +Imports: + stringr +Suggests: + covr Encoding: UTF-8 LazyData: true RoxygenNote: 7.2.3 + diff --git a/NAMESPACE b/NAMESPACE index 6ae9268..d7c0379 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,2 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(cmyk2rgb) +export(oxford_palettes) +importFrom(grDevices,col2rgb) +importFrom(stringr,str_pad) diff --git a/R/data.R b/R/data.R new file mode 100644 index 0000000..6e53ab8 --- /dev/null +++ b/R/data.R @@ -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" diff --git a/R/get_named_colours.R b/R/get_named_colours.R new file mode 100644 index 0000000..82b4e24 --- /dev/null +++ b/R/get_named_colours.R @@ -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 +} diff --git a/R/ox_palettes.R b/R/ox_palettes.R new file mode 100644 index 0000000..6d5c717 --- /dev/null +++ b/R/ox_palettes.R @@ -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")) +) + + + + + diff --git a/R/oxfordtheme-package.R b/R/oxfordtheme-package.R deleted file mode 100644 index c975f70..0000000 --- a/R/oxfordtheme-package.R +++ /dev/null @@ -1,15 +0,0 @@ -# -#' -#' University of Oxford Theme and Theme Components for 'ggplot2' -#' -#' Theme and theme components for 'ggplot2' based on University of Oxford's -#' visual identity guidelines . -#' -#' -#' @md -#' @name oxfordtheme -#' @docType package -#' @author Ernest Guevarra (ernest@@guevarra.io) -#' @keywords internal -# -"_PACKAGE" diff --git a/R/oxfordtheme.R b/R/oxfordtheme.R new file mode 100644 index 0000000..7b12bf3 --- /dev/null +++ b/R/oxfordtheme.R @@ -0,0 +1,17 @@ +#' +#' Oxford Theme and Theme Components +#' +#' Theme and theme components for 'ggplot2' based on University of Oxford's +#' visual identity guidelines +#' . +#' +#' +#' @md +#' @name oxfordtheme +#' @docType package +#' @author Ernest Guevarra (ernest@guevarra.io) +#' @keywords internal +#' @importFrom stringr str_pad +#' @importFrom grDevices col2rgb +#' +"_PACKAGE" diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 0000000..b3f7ffa --- /dev/null +++ b/R/utils.R @@ -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]))() +} diff --git a/README.Rmd b/README.Rmd index f83fab0..fe7a437 100644 --- a/README.Rmd +++ b/README.Rmd @@ -13,9 +13,13 @@ knitr::opts_chunk$set( ) ``` -# oxfordtheme: University of Oxford Theme and Theme Components for 'ggplot2' +# oxfordtheme: Oxford Theme and Theme Components +[![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) 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). diff --git a/README.md b/README.md index d015d8b..672c5ad 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,18 @@ -# oxfordtheme: University of Oxford Theme and Theme Components for ‘ggplot2’ +# oxfordtheme: Oxford Theme and Theme Components + +[![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) Theme and theme components for ‘ggplot2’ based on [University of diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..04c5585 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,14 @@ +comment: false + +coverage: + status: + project: + default: + target: auto + threshold: 1% + informational: true + patch: + default: + target: auto + threshold: 1% + informational: true diff --git a/data-raw/create_colour_df.R b/data-raw/create_colour_df.R new file mode 100644 index 0000000..b1743fb --- /dev/null +++ b/data-raw/create_colour_df.R @@ -0,0 +1,76 @@ +# Create table for Oxford colours from branding toolkit ------------------------ + +oxford_colours <- data.frame( + rbind( + c(Name="blue", Pantone=282, C=100, M=80, Y=0, K=60, R=0, G=33, B=71), + c(Name="blue1", Pantone=279, C=69, M=35, Y=0, K=0, R=72, G=145, B=220), + c(Name="blue2", Pantone=291, C=36, M=7, Y=2, K=0, R=158, G=206, B=235), + c(Name="blue3", Pantone=5405, C=78, M=51, Y=37, K=13, R=68, G=104, B=125), + c(Name="blue4", Pantone=549, C=65, M=27, Y=25, K=1, R=95, G=155, B=175), + c(Name="blue5", Pantone=551, C=36, M=12, Y=14, K=0, R=161, G=196, B=208), + c(Name="blue6", Pantone=562, C=88, M=34, Y=57, K=14, R=0, G=119, B=112), + c(Name="blue7", Pantone=624, C=55, M=23, Y=43, K=1, R=123, G=162, B=150), + c(Name="blue8", Pantone=559, C=27, M=7, Y=25, K=0, R=188, G=210, B=195), + c(Name="green1", Pantone=576, C=64, M=25, Y=100, K=7, R=105, G=145, B=59), + c(Name="green2", Pantone=578, C=30, M=6, Y=51, K=0, R=185, G=207, B=150), + c(Name="green3", Pantone=580, C=20, M=4, Y=37, K=0, R=206, G=219, B=175), + c(Name="green4", Pantone=583, C=39, M=17, Y=100, K=1, R=170, G=179, B=0), + c(Name="green5", Pantone=585, C=16, M=3, Y=69, K=0, R=219, G=222, B=114), + c(Name="green6", Pantone=587, C=12, M=2, Y=51, K=0, R=227, G=229, B=151), + c(Name="orange1", Pantone=7412, C=16, M=59, Y=96, K=2, R=207, G=122, B=48), + c(Name="orange2", Pantone=129, C=4, M=16, Y=84, K=0, R=245, G=207, B=71), + c(Name="orange3", Pantone=127, C=6, M=8, Y=66, K=0, R=243, G=222, B=116), + c(Name="red1", Pantone=202, C=31, M=95, Y=67, K=31, R=135, G=36, B=52), + c(Name="red2", Pantone=200, C=18, M=100, Y=83, K=8, R=190, G=15, B=52), + c(Name="red3", Pantone=196, C=6, M=25, Y=10, K=0, R=235, G=196, B=203), + c(Name="gray1", Pantone="Warm Gray 6", C=36, M=35, Y=38, K=1, R=167, G=157, B=150), + c(Name="gray2", Pantone="Warm Gray 3", C=22, M=19, Y=23, K=0, R=199, G=194, B=188), + c(Name="gray3", Pantone="Warm Gray 1", C=11, M=9, Y=12, K=0, R=224, G=222, B=217), + c(Name="gold", Pantone="872 (Gold)", C=0, M=21, Y=60, K=30, R=NA, G=NA, B=NA), + c(Name="silver", Pantone="877 (Silver)", C=51, M=40, Y=39, K=4, R=NA, G=NA, B=NA) + ) +) |> + dplyr::mutate(dplyr::across(.cols = C:B, .fns = as.integer)) + + +oxford_colours$hex <- c( + with( + oxford_colours[1:(nrow(oxford_colours) - 2), ], + rgb(R, G, B, maxColorValue = 255) + ), + NA_character_, NA_character_ +) + + + +## Colours from https://communications.web.ox.ac.uk/communications-resources/visual-identity/identity-guidelines/colours + +### Create session with colours URL ---- +session <- rvest::session("https://communications.web.ox.ac.uk/communications-resources/visual-identity/identity-guidelines/colours") + +### Process text ---- +oxford_colours <- session |> + rvest::html_elements(".layout-row p") |> + rvest::html_text() |> + (\(x) x[c(1:3, 5:6, 9:15, 17:19, 21:23, 25:31, 33:35, 37:39, 41:42)])() |> + stringr::str_split(pattern = "\n", simplify = TRUE) |> + (\(x) { x[32:33, 5] <- x[32:33, 2]; x[32:33, 2] <- ""; x })() |> + data.frame() |> + (\(x) { names(x) <- c("name", "rgb", "cmyk", "hex", "pantone"); x })() + +### Add Oxford blue ---- +oxford_colours <- rbind( + cbind(name = "Oxford blue", rgb = "RGB 0, 33, 71", cmyk = "CMYK 100, 87, 42, 51", hex = "#002147", pantone = "Pantone: 282"), + oxford_colours +) + +### Process fields ---- + +oxford_colours <- oxford_colours |> + dplyr::mutate( + rgb = stringr::str_remove_all(rgb, pattern = "RGB "), + cmyk = stringr::str_remove_all(cmyk, pattern = "CMYK "), + pantone = stringr::str_remove_all(pantone, pattern = "Pantone: |Pantone ") + ) + +usethis::use_data(oxford_colours, overwrite = TRUE, compress = "xz") diff --git a/data/oxford_colours.rda b/data/oxford_colours.rda new file mode 100644 index 0000000..ad1aa82 Binary files /dev/null and b/data/oxford_colours.rda differ diff --git a/man/cmyk2rgb.Rd b/man/cmyk2rgb.Rd new file mode 100644 index 0000000..bc08dae --- /dev/null +++ b/man/cmyk2rgb.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{cmyk2rgb} +\alias{cmyk2rgb} +\title{Convert CMYK to RGB} +\usage{ +cmyk2rgb(C, M, Y, K) +} +\arguments{ +\item{C}{An integer value for cyan} + +\item{M}{An integer value for magenta} + +\item{Y}{An integer value for yellow} + +\item{K}{An integer value for key (black)} +} +\value{ +A named vector for R, G, and B for RGB +} +\description{ +Convert CMYK to RGB +} +\examples{ +cmyk2rgb(100, 80, 0, 60) + +} diff --git a/man/oxford_colours.Rd b/man/oxford_colours.Rd new file mode 100644 index 0000000..663924a --- /dev/null +++ b/man/oxford_colours.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{oxford_colours} +\alias{oxford_colours} +\title{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 | +} +\source{ +https://communications.web.ox.ac.uk/communications-resources/visual-identity/identity-guidelines/colours +} +\usage{ +oxford_colours +} +\description{ +Oxford colours based on University of Oxford's visual identity guidelines +} +\examples{ +oxford_colours + +} +\keyword{datasets} diff --git a/man/oxford_palettes.Rd b/man/oxford_palettes.Rd new file mode 100644 index 0000000..951c7a6 --- /dev/null +++ b/man/oxford_palettes.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ox_palettes.R +\docType{data} +\name{oxford_palettes} +\alias{oxford_palettes} +\title{Complete list of Oxford colour palettes} +\format{ +An object of class \code{list} of length 5. +} +\usage{ +oxford_palettes +} +\description{ +Complete list of Oxford colour palettes +} +\keyword{datasets} diff --git a/man/oxfordtheme.Rd b/man/oxfordtheme.Rd index c484e6e..8dcff65 100644 --- a/man/oxfordtheme.Rd +++ b/man/oxfordtheme.Rd @@ -1,13 +1,14 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/oxfordtheme-package.R +% Please edit documentation in R/oxfordtheme.R \docType{package} \name{oxfordtheme} \alias{oxfordtheme} \alias{oxfordtheme-package} -\title{University of Oxford Theme and Theme Components for 'ggplot2'} +\title{Oxford Theme and Theme Components} \description{ Theme and theme components for 'ggplot2' based on University of Oxford's -visual identity guidelines \url{https://www.ox.ac.uk/sites/files/oxford/media_wysiwyg/Oxford\%20Blue\%20LR.pdf}. +visual identity guidelines +\url{https://www.ox.ac.uk/sites/files/oxford/media_wysiwyg/Oxford\%20Blue\%20LR.pdf}. } \author{ Ernest Guevarra (ernest@guevarra.io)