-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathREADME.Rmd
More file actions
133 lines (82 loc) · 5.77 KB
/
README.Rmd
File metadata and controls
133 lines (82 loc) · 5.77 KB
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
---
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 -->
[](https://codecov.io/gh/grattan/grattantheme?branch=master)
[](https://github.com/grattan/grattantheme/actions)
[](https://www.tidyverse.org/lifecycle/#stable)
[](https://github.com/grattan/grattantheme/actions/workflows/R-CMD-check.yaml)
<!-- 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. For charts with discrete values on the y axis, `theme_grattan(flipped = 'TRUE')` provides a vertical axis line and rotates gridlines.
Use `scale_y_continuous_grattan()` (or `scale_x_continuous_grattan` if flipped) to set default values for your vertical axis that will work well with most Grattan charts.
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.
Use `theme_grattan(background = "box")` to create a chart for a Grattan report box.
## Add chart annotations and notes
Use `grattan_label()`, `grattan_label_repel()`, or `grattan_arrow()` to add style-guide consistent annotations to your chart.
Use `labs(caption = "Notes: Your notes. Source: Your source.")` to add notes and sources, with text appropriately wrapped.
## Check how your chart looks
Use `check_chart_aspect_ratio()` to create a temporary pop-up chart to inspect chart appearances at different aspect ratios.
## 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 or LaTeX 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()`.
Use `set_overleaf_project("project_name")` and then `grattan_save_overleaf()` to conveniently save your chart to an ongoing Overleaf report project.
## 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.