forked from grattan/grattantheme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
121 lines (75 loc) · 5 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "75%"
)
devtools::load_all()
library(tidyverse)
```
<!-- badges: start -->
[![Codecov test coverage](https://codecov.io/gh/grattan/grattantheme/branch/master/graph/badge.svg)](https://codecov.io/gh/grattan/grattantheme?branch=master)
[![R build status](https://github.com/grattan/grattantheme/workflows/R-CMD-check/badge.svg)](https://github.com/grattan/grattantheme/actions)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable)
<!-- badges: end -->
# grattantheme
Create ggplot2 charts in the Grattan Institute style.
See the [grattantheme vignette](https://grattan.github.io/grattantheme/articles/using_grattantheme.html) to learn how to make your ggplot2 charts Grattan-y with `grattantheme`.
See the [Data Visualisation](https://grattan.github.io/R_at_Grattan/data-visualisation.html) chapter of `Using R at Grattan Institute` for more about how to make great charts.
## Install grattantheme
The grattantheme package needs to be downloaded and installed from Github. The easiest way to do this is with the devtools package. If you don't have the devtools package, install it:
`install.packages("devtools")`
Once devtools is installed, you can download and install grattantheme as follows:
`devtools::install_github("grattan/grattantheme", dependencies = TRUE, upgrade = "always")`
Once grattantheme is installed, you can load it the same way you normally load an R package:
`library(grattantheme)`
## Make your charts look nice
See the [grattantheme vignette](https://grattan.github.io/grattantheme/articles/using_grattantheme.html) for a more complete guide.
Use `theme_grattan()` to format your ggplot2 charts in a style consistent with the Grattan style guide, including elements such as gridline colours and line width, font size, etc. For scatter plots, `theme_grattan(chart_type = "scatter")` provides a black y-axis.
Use `grattan_y_continuous()` to set default values for your vertical axis that will work well with most Grattan charts.
Use `grattan_colour_manual(n)` or `grattan_fill_manual(n)` to format the `n` coloured elements of your `ggplot2` plot. These functions will choose appropriately-spaced Grattan colours, ordered from either light to dark or the reverse.
The colours that will be used in your plot are:
```{r show-cols-image, echo = FALSE, warning=FALSE, dpi=350}
library(tidyverse)
library(grattantheme)
make_col_tibble <- function(n) {
tibble(col = make_grattan_pal_discrete(n),
order = c(1:n),
n = n)
}
grattan_colours <- map_dfr(c(1:10), make_col_tibble)
grattan_colours$col <- factor(grattan_colours$col)
grattan_colours <- grattan_colours %>%
mutate(n_desc = if_else(n == 1, "n = 1", paste0(" ", n)))
col_plot <- grattan_colours %>%
ggplot(aes(x = reorder(n_desc, -n),
y = order,
fill = col)) +
geom_tile(col = "white", linewidth = 1) +
scale_fill_manual(values = levels(grattan_colours$col)) +
coord_flip(expand = FALSE, ylim = c(0, 13)) +
theme_grattan() +
theme(panel.grid = element_blank(),
axis.title = element_blank(),
axis.ticks = element_blank(),
axis.line = element_blank(),
axis.text.x = element_blank())
col_plot
```
A range of colours from the style guide (such as `grattan_lightorange`, `grattan_darkred`, and so on) are defined for your convenience. Each colour has eight tints available, e.g. `grattan_lightorange` has lighter variants `grattan_lightorange1` through `grattan_lightorange8` (closest to white). These can be used to allow highlighting or when filling in block colours behind text, such as when designing tables.
## Save your nice looking charts
Use `grattan_save()` to save your ggplot2 charts (eg. as `.png` or `.pdf` files) for use elsewhere, such as in Powerpoint, LaTeX, or the Grattan Blog, with the size and resolution set to style guide-consistent values. You can save your charts in a variety of sizes and styles (see `?grattan_save()` for a list).
Want to save your chart as a Powerpoint file? Use `grattan_save(save_pptx = TRUE)` or the standalone `grattan_save_pptx()` function.
Want to save your chart and accompanying data as a properly-formatted .xlsx workbook? Use `grattan_save(save_data = TRUE)` or the
standalone `save_chartdata()` function.
Save your chart in all Grattan formats - along with chart data - using `grattan_save_all()`.
## Save animated charts
Use `grattan_anim_save()` to save gganimate animations formatted in the Grattan style.
## Notes
Some graph defaults (such as colour) will be modified during your R session; restart R to restore all defaults.
Some manual modification to your chart will most likely be required in order to make it fully consistent with the style guide, just as it would in other visualisation software or Excel/Powerpoint.