Skip to contents

Overview

The unhcrthemes package provides a ggplot2 theme and a set of colour palettes for making charts and graphics based on UNHCR Data Visualization Guidelines. The goal of this package is to ease and speed up the creation of charts, while promoting the UNHCR visual identity with a predefined ggplot theme, as well as a set of colour palettes and scales.

Installation

This package is not on yet on CRAN and to install it, you will need the remotes package.

install.packages("remotes")
remotes::install_github("vidonne/unhcrthemes")

Content

A package with all necessary elements to quickly implement UNHCR Brand style in your statistical products and data stories:

  1. Adjusted ggplot2 theme
  2. A series of color palette for:
    • A categorical palette for UNHCR main data visualization colors
    • A categorical palette for people of concern to UNHCR categories
    • A categorical palette for geographical regional divisions of UNHCR
    • Six sequential color palettes for all the main data visualization colors
    • Two recommended diverging color palette

Fonts

UNHCR uses Lato as its main font for publications and data visualizations. Arial can also be used as a fallback option if it is not possible to install Lato on your computer.

Usage

Base ggplot2 theme

data(idp, package = "unhcrthemes")

idp_total <- idp |>
  group_by(year) |>
  summarise(idp = sum(idp, na.rm = TRUE) / 1e6) |>
  ungroup()


glimpse(idp_total)
#> Rows: 10
#> Columns: 2
#> $ year <int> 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 20…
#> $ idp  <dbl> 10.32914, 11.62813, 10.76541, 13.48312, 16.31171, …
ggplot(idp_total) +
  geom_col(aes(x = year, y = idp),
           width = 0.8) +
  labs(title = "Globalement IDP displacement | 2010 - 2020",
       y = "Number of people (in million)",
       caption = "Source: UNHCR Refugee Data Finder\n© UNHCR, The UN Refugee Agency") +
  scale_y_continuous(expand = expansion(c(0, 0.1))) +
  scale_x_continuous(breaks = pretty_breaks(10)) +
  theme_unhcr(grid = "Y", axis_title = "y")

UNHCR color palette

All recommended data visualization colors are accessible as palettes or scales (color/fill).

Base theme and color scale

ggplot(idp_total) +
  geom_col(aes(x = year, y = idp),
           fill = unhcr_pal(n = 1, "pal_blue"),
           width = 0.8) +
  labs(title = "Globalement IDP displacement | 2010 - 2020",
       y = "Number of people (in million)",
       caption = "Source: UNHCR Refugee Data Finder\n© UNHCR, The UN Refugee Agency") +
  scale_y_continuous(expand = expansion(c(0, 0.1))) +
  scale_x_continuous(breaks = pretty_breaks(10)) +
  theme_unhcr(grid = "Y", axis_title = "y")

idp_total_sex <- idp |>
  group_by(year, sex) |>
  summarise(idp = sum(idp, na.rm = TRUE) / 1e6) |>
  ungroup()
#> `summarise()` has grouped output by 'year'. You can override using the `.groups` argument.

glimpse(idp_total_sex)
#> Rows: 20
#> Columns: 3
#> $ year <int> 2010, 2010, 2011, 2011, 2012, 2012, 2013, 2013, 20…
#> $ sex  <chr> "female", "male", "female", "male", "female", "mal…
#> $ idp  <dbl> 5.158210, 5.170928, 5.874562, 5.753568, 5.389737, …
ggplot(idp_total_sex) +
  geom_col(aes(x = year, y = idp, fill = sex),
           width = 0.8,
           position = position_dodge(width = 0.9)) +
  scale_fill_unhcr_d(palette = "pal_unhcr") +
  scale_y_continuous(expand = expansion(c(0, 0.1))) +
  labs(title = "Globalement IDP displacement | 2010 - 2020",
       y = "Number of people (in million)",
       caption = "Source: UNHCR Refugee Data Finder\n© UNHCR, The UN Refugee Agency") +
  scale_x_continuous(breaks = pretty_breaks(10)) +
  theme_unhcr(grid = "Y", axis_title = "y")

UNHCR packages

unhcrthemes is part of unhcrverse, a set of packages to ease the production of statistical evidence and data stories.

You can install them all with the following:

## unhcrdown
remotes::install_github("vidonne/unhcrdown")
## unhcrthemes
remotes::install_github("vidonne/unhcrthemes")
## unhcrdatapackage
remotes::install_github('unhcr/unhcrdatapackage')
## hcrdata
remotes::install_github('unhcr-web/hcrdata')
## HighFrequencyChecks
remotes::install_github('unhcr/HighFrequencyChecks')
## koboloadeR
remotes::install_github('unhcr/koboloadeR')

Getting help

Please report any issues or bugs on GitHub, try to include a minimal reproducible example to help us understand.

Code of Conduct

Please note that the mynewpack project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.