-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathREADME.Rmd
More file actions
153 lines (117 loc) · 6.13 KB
/
README.Rmd
File metadata and controls
153 lines (117 loc) · 6.13 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
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-",
fig.retina = 2,
dpi = 300,
dev = "ragg_png"
)
```
# unhcrthemes <img src='man/figures/logo.svg' align="right" alt="unhcrthemes package hex sticker" width="140" alt="unhcrthemes package hex sticker" />
<!-- badges: start -->
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://github.com/unhcr-dataviz/unhcrthemes/actions/workflows/R-CMD-check.yaml)
[](https://CRAN.R-project.org/package=unhcrthemes)
<!-- badges: end -->
Simplify the creation of your data visualizations with the `{unhcrthemes}` R package. It is designed to align your plots with [UNHCR's data visualization](https://dataviz.unhcr.org/guidance/) recommendations. This package offers a comprehensive `{ggplot2}` theme, including built-in customizations and thoughtfully crafted color palettes.
## Features
- A consistent and appealing `{ggplot2}` theme that matches [UNHCR Data Visualization Guidelines](https://dataviz.unhcr.org/guidance/).
- A collection of color palettes ensuring your plots are consistent with [UNHCR's color scheme](https://dataviz.unhcr.org/guidance/).
- Easy-to-use functions to apply the theme and color palettes to your `{ggplot2}` plots.
## Installation
Get started by installing the `{unhcrthemes}` package from CRAN with:
```{r install, eval=FALSE}
install.packages("unhcrthemes")
```
Or retrieve the development version from Github using the `{pak}` package:
```{r pak, eval=FALSE}
# If pak is not yet installed, uncomment the following line:
# install.packages("pak")
pak::pkg_install("unhcr-dataviz/unhcrthemes")
```
## Usage
```{r load, message = FALSE, warning = FALSE}
# Load required packages
library(ggplot2)
library(unhcrthemes)
```
### Base `{ggplot2}` theme
```{r base-plot, message = FALSE, warning = FALSE, out.width="90%", fig.align="center"}
# Apply the theme_unhcr() to your plot
ggplot(
mtcars,
aes(x = hp, y = mpg)
) +
geom_point() +
labs(
title = "Simple scatterplot with ggplot",
subtitle = "This plot shows the default style of theme_unhcr()",
x = "Horsepower (hp)",
y = "Fuel efficiency (mpg)",
caption = "Source: mtcars"
) +
theme_unhcr()
```
### Fonts
One of the two officially recommended fonts outlined in the [UNHCR Data Visualization Guidelines](https://dataviz.unhcr.org/guidance/) is [`Lato`](https://fonts.google.com/specimen/Lato). To ensure optimal functionality of the `{unhcrthemes}` package, please make sure that the `Lato` font is installed on your device prior to usage.
For `R` PDF (`pdf`) and PostScript (`postcript`) devices, there is a function `import_lato` that can be used to import the `Lato` font into these two devices. We recommend the use of `cairo_pdf` or `cairo_ps` devices, which work when you have `Lato` installed. They are available on all platforms and have better support custom fonts.
### Color palettes
Choose from a variety of carefully curated color palettes that harmonize with UNHCR's visual identity.
```{r palette-all, message = FALSE, warning = FALSE, out.width="90%", fig.align="center", fig.height=6}
# Display all unhcr color palette
display_unhcr_all()
```
```{r palette-blue, message = FALSE, warning = FALSE, out.width="90%", fig.align="center", fig.height=2}
# Or select a specific one and limit the number of colors
display_unhcr_pal(n = 3, "pal_blue")
```
### Scales (color/fill)
```{r scale-plot, message = FALSE, warning = FALSE, out.width="90%", fig.align="center"}
# Add color scale to your plot
ggplot(
mtcars,
aes(x = hp, y = mpg, color = as.factor(cyl))
) +
geom_point(alpha = .8) +
labs(
title = "Simple scatterplot with ggplot",
subtitle = "This plot shows the default style of theme_unhcr()",
x = "Horsepower (hp)",
y = "Fuel efficiency (mpg)",
color = "Number of cylinder",
caption = "Source: mtcars"
) +
scale_color_unhcr_d() +
theme_unhcr(legend_title = TRUE)
```
### Geoms (text/label)
```{r geom-plot, message = FALSE, warning = FALSE, out.width="90%", fig.align="center", fig.height=4}
# Default Lato font also apply for geom_text and label
dplyr::count(mpg, class) |>
dplyr::arrange(n) |>
dplyr::mutate(class = factor(class, levels = class)) |>
ggplot(aes(n, class)) +
geom_col(fill = unhcr_pal(n = 1, "pal_blue")) +
geom_text(aes(label = n), hjust = 0, nudge_x = 1) +
labs(
title = "Simple bar chart with labels using ggplot",
subtitle = "This plot shows the default style of theme_unhcr()",
caption = "Source: mtcars"
) +
scale_x_continuous(expand = expansion(c(0, 0.1))) +
theme_unhcr(grid = FALSE, axis = "y", axis_title = FALSE, axis_text = "y")
```
Explore more examples of `{unhcrthemes}` in action on the [package vignette](https://unhcr-dataviz.github.io/unhcrthemes/articles/unhcrthemes.html) or [UNHCR Data Visualization Platform](https://dataviz.unhcr.org/tutorials/r/).
```{r child="man/rmdfragments/unhcr_tools.Rmd"}
```
## Acknowledgements
We extend our gratitude to the creators of the [`{hrbrthemes}`](https://github.com/hrbrmstr/hrbrthemes), [`{rcartocolor}`](https://github.com/Nowosad/rcartocolor) and [`{cowplot}`](https://github.com/wilkelab/cowplot/) packages that influenced the development of `{unhcrthemes}`.
## Contribution and Code of Conduct
Contributions to `{unhcrthemes}` are highly valued. To ensure a welcoming and inclusive community, we follow our [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). If you have suggestions, uncover bugs, or envision new features, kindly submit an [issue on GitHub](https://github.com/unhcr-dataviz/unhcrthemes/issues). To contribute code, don't hesitate to fork the repository and create a pull request.
## License
This package is distributed under the [MIT License](https://github.com/unhcr-dataviz/unhcrthemes/blob/master/LICENSE.md).