-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
136 lines (90 loc) · 3.82 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
<!-- badges: start -->
[](https://github.com/DfE-R-Community/ggdfe/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
dpi = 300
)
```
# ggdfe
```{r, echo=FALSE, message=FALSE}
devtools::load_all(".")
knitr::opts_chunk$set(echo = FALSE) # if you want code chunks to be displayed, best to do it in the chunk headers
```
This package seeks to create an easy theme to add to any ggplot to keep it in line with DfE brand guidelines. Simply transforms existing ggplots into the house style of the Department for Education.
```{r, echo=FALSE, message=FALSE, fig.asp= .6, out.width="90%"}
ggplot(data = iris, aes(x=Petal.Length, y=Sepal.Length, colour = Species))+
geom_jitter(size = 2, alpha = .7)+
scale_colour_dfe()+
geom_smooth(method = "lm", se = FALSE)+
theme_dfe_light()+
labs(title = "ggdfe",
subtitle = "Turn ggplots into DfE house style and colours")
```
## Colours
There are two functions that work to add in colour scales: `scale_fill_dfe()` and `scale_colour_dfe()`. These replace the usual `scale_colour_*()` and `scale_fill_*()` functions to change colours on ggplot.
These are the base colours
```{r, fig.asp= .2, out.width="80%"}
tibble::tibble(y=max(length(dfe_colours)),x=dfe_colours[!grepl("_l", names(dfe_colours))]) -> data
ggplot2::ggplot(data=data, ggplot2::aes(x=names(x),y=y, fill = x))+
ggplot2::geom_tile(width=.9,height=.9, colour = '#e5e5e5', linewidth = .5)+
ggplot2::scale_fill_manual(values = levels(factor(data$x)))+
ggplot2::coord_fixed(ratio=9/16)+
ggplot2::theme_void()+
ggplot2::theme(legend.position = 'none',
axis.text.x = ggplot2::element_text())
```
There are also palettes, passed to the 'palettes' argument. These are for selecting a suitable subset of the colours above, depending on if you need a discrete, continuous or diverging palette.
- main - Blue red turquoise (discrete, 3 colours)
- warm - Red to purple (continuous)
- cool - Blue to lime (continuous)
- full - all colours in the brand (discrete, 7 colours)
- likert - red to blue, grey midpoint (diverging)
- likert2 - green to purple, white midpoint (diverging)
- likert3 - red to blue, white midpoint (diverging)
- heat - white to red (continuous)
- heat2 - white to pink (continuous)
- cold - white to blue (continuous)
- cold2 - white to turqouise (continuous)
- pale - paler palettes for big blocks of colour (bar charts or treemaps)
```{r}
show_dfe_palettes()
```
Examples of usage would be:
Light theme
```{r, echo = TRUE, fig.asp= .6, out.width="90%"}
ggplot2::ggplot(data = iris)+
ggplot2::aes(x=Sepal.Length, colour = Species)+
ggplot2::geom_density(linewidth = 1.5)+
scale_colour_dfe(palette = "main")+
labs(title = "Default title is in dark blue",
subtitle = "Default subtitle and copy text are dark grey",
caption = "Using theme_dfe_light()")+
theme_dfe_light()
```
Dark theme
```{r, echo = TRUE, fig.asp=.6, out.width = "90%"}
ggplot2::ggplot(data = iris)+
ggplot2::aes(x=Sepal.Length, colour = Species)+
ggplot2::geom_density(linewidth = 1.5)+
scale_colour_dfe(palette = "likert")+
labs(title = "Dark title is pale blue",
subtitle = "Dark subtitle and copy text are pale grey",
caption = "Using theme_dfe_dark()")+
theme_dfe_dark()
```
For clearer plot boundaries, there is also `theme_nimbus()`.
```{r, echo = TRUE, fig.asp= .6, out.width="90%"}
plot <- ggplot(ggplot2::diamonds, aes(carat, price)) + geom_point() +
labs(title = "Theme_nimbus",
subtitle = "",
caption = "theme_nimbus()")
plot + theme_nimbus()
```