MyNixOS website logo
Description

UNHCR 'ggplot2' Theme and Colour Palettes.

A 'ggplot2' theme and color palettes following the United Nations High Commissioner for Refugees (UNHCR) Data Visualization Guidelines recommendations.

unhcrthemes unhcrthemes package hex sticker

Project Status: Active – The project has reached a stable, usablestate and is being activelydeveloped. R-CMD-check CRANstatus

Simplify the creation of your data visualizations with the {unhcrthemes} R package. It is designed to align your plots with UNHCR’s data visualization recommendations. This package offers a comprehensive {ggplot2} theme, including built-in customizations and thoughtfully crafted color palettes.

Features

Installation

Get started by installing the {unhcrthemes} package from CRAN with:

install.packages("unhcrthemes")

Or retrieve the development version from Github using the {pak} package:

# If pak is not yet installed, uncomment the following line:
# install.packages("pak")

pak::pkg_install("unhcr-dataviz/unhcrthemes")

Usage

# Load required packages
library(ggplot2)
library(unhcrthemes)

Base {ggplot2} theme

# 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 is 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.

# Display all unhcr color palette
display_unhcr_all()
# Or select a specific one and limit the number of colors
display_unhcr_pal(n = 3, "pal_blue")

Scales (color/fill)

# 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)

# 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 or UNHCR Data Visualization Platform.

Additional UNHCR Tools

Acknowledgements

We extend our gratitude to the creators of the {hrbrthemes}, {rcartocolor} and {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. If you have suggestions, uncover bugs, or envision new features, kindly submit an issue on GitHub. To contribute code, don’t hesitate to fork the repository and create a pull request.

License

This package is distributed under the MIT License.

Metadata

Version

0.6.2

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows