Skip to content

Commit

Permalink
Merge pull request #30 from OxfordIHTM/dev
Browse files Browse the repository at this point in the history
re-factor utilities
  • Loading branch information
ernestguevarra authored Feb 29, 2024
2 parents 67407e1 + 0b9d583 commit d3988a4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ License: GPL (>= 3)
Depends:
R (>= 2.10)
Imports:
stringr
stringr,
withr
Suggests:
covr,
sf
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ importFrom(graphics,par)
importFrom(graphics,rect)
importFrom(graphics,text)
importFrom(stringr,str_pad)
importFrom(withr,with_par)
1 change: 1 addition & 0 deletions R/oxfordtheme.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
#' @importFrom stringr str_pad
#' @importFrom grDevices col2rgb rgb colorRampPalette
#' @importFrom graphics rect par image text
#' @importFrom withr with_par
#'
"_PACKAGE"
13 changes: 9 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ print.palette <- function(x, ...) {
# old <- par(mar = c(0.5, 0.5, 0.5, 0.5))
# on.exit(par(old))

image(1:n, 1, as.matrix(1:n), col = x,
ylab = "", xaxt = "n", yaxt = "n", bty = "n")
withr::with_par(
new = list(mar = c(0.5, 0.5, 0.5, 0.5)),
code = {
image(1:n, 1, as.matrix(1:n), col = x,
ylab = "", xaxt = "n", yaxt = "n", bty = "n")

rect(0, 0.9, n + 1, 1.1, col = rgb(1, 1, 1, 0.8), border = NA)
text((n + 1) / 2, 1, labels = attr(x, "name"), cex = 1, family = "serif")
rect(0, 0.9, n + 1, 1.1, col = rgb(1, 1, 1, 0.8), border = NA)
text((n + 1) / 2, 1, labels = attr(x, "name"), cex = 1, family = "serif")
}
)
}
10 changes: 5 additions & 5 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ oxford_colours |>
knitr::kable()
```

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

Expand All @@ -87,7 +87,7 @@ Based on the [University of Oxford](https://ox.ac.uk)'s [visual identity guideli
oxford_theme_palettes()$heritage
```

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

Expand All @@ -97,7 +97,7 @@ structure(oxford_theme_palettes()$heritage, class = "palette", name = "heritage"
oxford_theme_palettes()$contemporary
```

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

Expand All @@ -107,7 +107,7 @@ structure(oxford_theme_palettes()$contemporary, class = "palette", name = "conte
oxford_theme_palettes()$celebratory
```

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

Expand All @@ -117,7 +117,7 @@ structure(oxford_theme_palettes()$celebratory, class = "palette", name = "celebr
oxford_theme_palettes()$corporate
```

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

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ the following colours are available from this package:
| Gold | | | | 10122C |
| Silver | | | | 10103C |

![](man/figures/README-oxford-colours-graphic-1.png)<!-- -->
<img src="man/figures/README-oxford-colours-graphic-1.png" style="display: block; margin: auto;" />

You can access either the name, RGB, CMYK, hex code, and/or Pantone
values of each Oxford colour through the `get_oxford_colours()` function
Expand Down Expand Up @@ -136,7 +136,7 @@ oxford_theme_palettes()$heritage
#> [1] "#994636" "#E08D79" "#C4A29E" "#A0AF84" "#426A5A"
```

![](man/figures/README-oxford-palettes-heritage-show-1.png)<!-- -->
<img src="man/figures/README-oxford-palettes-heritage-show-1.png" style="display: block; margin: auto;" />

#### Contemporary

Expand All @@ -145,7 +145,7 @@ oxford_theme_palettes()$contemporary
#> [1] "#FE615A" "#ED9390" "#E4F0EF" "#789E9E" "#00AAB4"
```

![](man/figures/README-oxford-palettes-contemporary-show-1.png)<!-- -->
<img src="man/figures/README-oxford-palettes-contemporary-show-1.png" style="display: block; margin: auto;" />

#### Celebratory

Expand All @@ -154,7 +154,7 @@ oxford_theme_palettes()$celebratory
#> [1] "#15616D" "#776885" "#E2C044" "#D4CDF4" "#7F055F"
```

![](man/figures/README-oxford-palettes-celebratory-show-1.png)<!-- -->
<img src="man/figures/README-oxford-palettes-celebratory-show-1.png" style="display: block; margin: auto;" />

#### Corporate

Expand All @@ -163,7 +163,7 @@ oxford_theme_palettes()$corporate
#> [1] "#FB5607" "#B9D6F2" "#95C11F" "#49B6FF" "#1D42A6"
```

![](man/figures/README-oxford-palettes-corporate-show-1.png)<!-- -->
<img src="man/figures/README-oxford-palettes-corporate-show-1.png" style="display: block; margin: auto;" />

### Oxford theme paletttes for use in plotting

Expand Down

0 comments on commit d3988a4

Please sign in to comment.