This repository has been archived by the owner on Apr 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathREADME.Rmd
118 lines (73 loc) · 3.32 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
[![Travis build status](https://travis-ci.org/ukgovdatascience/govstyle.svg?branch=master)](https://travis-ci.org/ukgovdatascience/govstyle)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/nacnudus/govstyle?branch=master&svg=true)](https://ci.appveyor.com/project/nacnudus/govstyle)
[![Code coverage](http://codecov.io/github/ukgovdatascience/govstyle/coverage.svg?branch=master)](http://codecov.io/github/ukgovdatascience/govstyle?branch=master)
[![GitHub tag](https://img.shields.io/github/tag/ukgovdatascience/govstyle.svg)]()
# govstyle
A package for applying a [gov.uk](http://govuk-elements.herokuapp.com/) style to plots created in the R package [ggplot2](https://github.com/hadley/ggplot2).
This package *is in an early stage of development*; the intended end point is that it should be fully compliant with the gov.uk style guide.
This package turns plots from this:
![Basic ggplot2 plot](https://github.com/ukgovdatascience/govstyle/raw/master/vignettes/figure/figure1-1.png)
to this:
![govstyle plot](https://raw.githubusercontent.com/ukgovdatascience/govstyle/master/vignettes/figure/figure1d-1.png)
The best source of docmentation is the [vignettes](https://github.com/ukgovdatascience/govstyle/blob/master/vignettes/absence_statistics.md).
## Installation
To install, the package `devtools` is required, and can be installed with `install.packages('devtools')`.
`govstyle` can then be installed using `devtools::install_github('ukgovdatascience/govstyle')`.
Some users may not be able to use the `devtools::install_github()` commands as a result of network security settings.
If this is the case, `govstyle` can be installed by downloading the [zip of the repository](https://github.com/ukgovdatascience/govstyle/archive/master.zip) and installing the package locally using `devtools::install_local(<path to zip file>)`.
### Installing older versions
The package was revamped somewhat in January 2019. If this breaks your existing
code, try installling the original version with the following code.
```{r, eval = FALSE}
devtools::install_github("ukgovdatascience/govstyle", ref = "5d09353b14ccafda4e9c8676993fabf44fcfe5c1")
```
## Functions
* `theme_gov()`: Theme to be applied to plots produced in [ggplot2]() to give a government statistics publication feel.
* `gov_cols`: A vector of the [gov.uk](http://govuk-elements.herokuapp.com/colour/#colour-extended-palette) extended palette.
* `check_pal()`: Display the extended gov.uk palette in a pie chart.
## Examples
See [Vignette](https://github.com/ukgovdatascience/govstyle/blob/master/vignettes/absence_statistics.md) for in depth usage examples.
### theme_gov
```{r, echo=FALSE, include=FALSE}
knitr::opts_chunk$set(
warning = FALSE,
message = FALSE,
error = FALSE
)
```
```{r}
library(ggplot2)
library(dplyr)
#devtools::install_github("ukgovdatascience/govstyle")
library(govstyle)
```
```{r ggplot_theme_gov}
p <- mtcars %>%
ggplot +
aes(
x = wt,
y = mpg,
col = factor(cyl)
) +
geom_point()
p
p +
theme_gov()
```
### check_pal
```{r check_pal}
## Show gov.uk colours
check_pal()
## Show a subset of gov.uk colours
## Choose n colours:
check_pal(2)
check_pal(3)
check_pal(4)
## Pick a range of colours
check_pal(3:8)
check_pal(c(1,10))
## Pick colours manually
check_pal(
x = gov_cols[c("green", "grass_green")]
)
```