-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
136 lines (99 loc) · 5.23 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
136
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
warning = FALSE,
error = FALSE,
message = FALSE,
comment = "#>",
fig.path = "man/figures/README-",
dev = "svg"
)
ex1_alt <- paste("A bar chart with grey background, white grid lines",
"and dark grey bars.")
ex2_alt <- paste("A bar chart with white background,",
"light grey horizontal grid lines dark blue bars.")
```
# afcharts <img src="man/figures/logo.svg" alt="afcharts logo" align="right" height="150"/>
<!-- badges: start -->
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/best-practice-and-impact/afcharts)](https://github.com/best-practice-and-impact/afcharts/releases/latest) [![R build status](https://github.com/best-practice-and-impact/afcharts/workflows/R-CMD-check/badge.svg)](https://github.com/best-practice-and-impact/afcharts/actions)
[![R-CMD-check](https://github.com/best-practice-and-impact/afcharts/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/best-practice-and-impact/afcharts/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
afcharts is an R package for creating accessible plots by the Government Analysis Function. Currently, functions are available for styling ggplot2 plots.
The package has been developed using the [Government Analysis Function Data Visualisation guidance](https://analysisfunction.civilservice.gov.uk/policy-store/data-visualisation-charts/). afcharts should be used in conjunction with these guidance documents.
More information about the package and its functions can be found on the [afcharts website](https://best-practice-and-impact.github.io/afcharts/). In particular, the [cookbook](https://best-practice-and-impact.github.io/afcharts/articles/cookbook.html) contains lots of examples.
## Installation
### Install from CRAN
Install the latest release version of afcharts directly from CRAN:
``` {r install from CRAN, eval=FALSE}
install.packages("afcharts")
```
### Install from GitHub
afcharts can be installed directly from GitHub.
``` {r install from GitHub, eval=FALSE}
remotes::install_github(
"best-practice-and-impact/afcharts",
upgrade = "never",
build_vignettes = TRUE,
dependencies = TRUE
)
```
## Getting Started
Once installed, afcharts can be loaded using the `library()` function:
``` r
library(afcharts)
```
Help files for each function in the package can be found on the [References](https://best-practice-and-impact.github.io/afcharts/reference/) page of the package website. Alternatively, type `?function_name` into the RStudio console. For example:
``` r
?theme_af()
```
### Use afcharts as default
The easiest way to use afcharts is by adding `use_afcharts()` to the beginning of your R script, Rmarkdown document or Shiny app code. This function will set a number of defaults to ggplot2 geoms, use afcharts colour palettes and use `theme_af()`.
#### Example 1: Plot with one colour using ggplot2 defaults
```{r ex1, fig.alt = ex1_alt}
library(ggplot2)
library(dplyr)
library(gapminder)
library(afcharts)
gapminder |>
filter(year == 2007 & continent == "Europe") |>
slice_max(order_by = lifeExp, n = 5) |>
ggplot() +
geom_col(aes(x = reorder(country, -lifeExp), y = lifeExp)) +
scale_y_continuous(expand = c(0, 0)) +
labs(
x = NULL,
y = NULL,
title = "Iceland has the highest life expectancy in Europe",
subtitle = "Life expectancy in European countries, 2007",
caption = "Source: Gapminder"
)
```
#### Example 2: Plot with one colour using afcharts defaults
```{r ex2, fig.alt = ex2_alt}
afcharts::use_afcharts()
gapminder |>
filter(year == 2007 & continent == "Europe") |>
slice_max(order_by = lifeExp, n = 5) |>
ggplot() +
geom_col(aes(x = reorder(country, -lifeExp), y = lifeExp)) +
scale_y_continuous(expand = c(0, 0)) +
labs(
x = NULL,
y = NULL,
title = "Iceland has the highest life expectancy in Europe",
subtitle = "Life expectancy in European countries, 2007",
caption = "Source: Gapminder"
)
```
**Note on use of titles, subtitles and captions** <br> Titles, subtitles and captions have been embedded in these example charts for demonstration purposes. However, for accessibility reasons, it is usually preferable to provide titles in the body of the page rather than embedded within the image of the plot. More information is available in the [accessibility article](https://best-practice-and-impact.github.io/afcharts/articles/accessibility.html#other-accessibility-considerations).
## Acknowledgments
The afcharts package is based on the [sgplot](https://scotgovanalysis.github.io/sgplot/index.html) package, written by Alice Hannah.
## Licence
Unless stated otherwise, the codebase is released under [the MIT License](LICENSE). This covers both the codebase and any sample code in the documentation.
The documentation is [© Crown copyright](https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/) and available under the terms of the [Open Government 3.0](https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/) licence.