Skip to content

Commit 887047a

Browse files
authored
Merge pull request #37 from unhcr-dataviz/colours_revision
Update colours and style to align with the 2025 UNHCR Data Visualization Guidelines
2 parents faa51f7 + 57883af commit 887047a

15 files changed

Lines changed: 910 additions & 438 deletions

NEWS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# unhcrthemes (development version)
22

3+
## Updates aligned with 2025 UNHCR Data Visualization Guidelines
4+
5+
- Updated `theme_unhcr()` to reflect revised text and gridline colors based on the latest UNHCR standards.
6+
- Revised existing color palettes for improved clarity, contrast, and alignment with new data visualization guidance.
7+
- Added new categorical, sequential and diverging color palettes recommended in the 2025 guidelines.
8+
9+
*Note: Existing palettes remain available but may have slight adjustments. Deprecated colors will be phased out in a future release.*
10+
11+
For reference, see the [UNHCR Data Visualization Guidelines (2025)](https://dataviz.unhcr.org/guidance/) for more details.
12+
313
# unhcrthemes 0.6.3
414

515
## Minor improvements and fixes

R/display_unhcr_pal.R

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,16 @@ display_unhcr_all <- function(n = NULL, type = "all") {
4747
)
4848
on.exit(par(oldpar))
4949
max_my_n <- max(my_n)
50-
plot(1, 1,
51-
xlim = c(-1.5, max_my_n), ylim = ylim,
52-
type = "n", axes = FALSE, bty = "n", xlab = "", ylab = ""
50+
plot(
51+
1,
52+
1,
53+
xlim = c(-1.5, max_my_n),
54+
ylim = ylim,
55+
type = "n",
56+
axes = FALSE,
57+
bty = "n",
58+
xlab = "",
59+
ylab = ""
5360
)
5461

5562
for (i in seq_len(n_colors)) {
@@ -63,13 +70,9 @@ display_unhcr_all <- function(n = NULL, type = "all") {
6370
xright = 1:my_n[i],
6471
ytop = i - 0.2,
6572
col = one_color,
66-
border = "light grey"
67-
)
68-
text(-0.1, i - 0.6,
69-
labels = selected_metadata$name[i],
70-
xpd = TRUE,
71-
adj = 1
73+
border = "white"
7274
)
75+
text(-0.1, i - 0.6, labels = selected_metadata$name[i], xpd = TRUE, adj = 1)
7376
}
7477
}
7578

@@ -91,9 +94,16 @@ display_unhcr_all <- function(n = NULL, type = "all") {
9194
display_unhcr_pal <- function(n = NULL, name) {
9295
selected_colors <- unhcr_pal(n, name)
9396
selected_type <- unhcrcolors[unhcrcolors$name == name, ][["type"]][[1]]
94-
image(1:n, 1, as.matrix(1:n),
97+
image(
98+
1:n,
99+
1,
100+
as.matrix(1:n),
95101
col = selected_colors,
96102
main = paste0(name, ": ", selected_type, " (", n, ")"),
97-
xlab = " ", ylab = " ", xaxt = "n", yaxt = "n", bty = "n"
103+
xlab = " ",
104+
ylab = " ",
105+
xaxt = "n",
106+
yaxt = "n",
107+
bty = "n"
98108
)
99109
}

R/palettes.R

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
#' @examples
1313
#' unhcr_pal(3, "pal_unhcr")
1414
#' unhcr_pal(3, "pal_blue")
15-
#' unhcr_pal(5, "pal_navy")
15+
#' unhcr_pal(5, "pal_yellow")
1616
#' unhcr_pal(12, "pal_red")
1717
#' @export
18-
unhcr_pal <- function(n = NULL, name, ...){
19-
if (!(name %in% unhcrcolors$name)){
20-
stop(paste(name, "is not a valid palette name\n"),
21-
call. = FALSE)
18+
unhcr_pal <- function(n = NULL, name, ...) {
19+
if (!(name %in% unhcrcolors$name)) {
20+
stop(paste(name, "is not a valid palette name\n"), call. = FALSE)
2221
}
2322
selected_metadata <- unhcrcolors[unhcrcolors$name == name, ]
2423
min_n <- selected_metadata$min_n
@@ -32,14 +31,32 @@ unhcr_pal <- function(n = NULL, name, ...){
3231
proper_n <- max_n
3332
}
3433
if (!(n %in% min_n:max_n) && type == "qualitative") {
35-
warning(paste("Number of colors (n) in the", name,
36-
"palette should be between", min_n, "and", max_n,
37-
"\n"), call. = FALSE)
34+
warning(
35+
paste(
36+
"Number of colors (n) in the",
37+
name,
38+
"palette should be between",
39+
min_n,
40+
"and",
41+
max_n,
42+
"\n"
43+
),
44+
call. = FALSE
45+
)
3846
}
3947
if (n < min_n) {
40-
warning(paste("Number of colors (n) in the", name,
41-
"palette should be between", min_n, "and",
42-
max_n, "\n"), call. = FALSE)
48+
warning(
49+
paste(
50+
"Number of colors (n) in the",
51+
name,
52+
"palette should be between",
53+
min_n,
54+
"and",
55+
max_n,
56+
"\n"
57+
),
58+
call. = FALSE
59+
)
4360
proper_n <- min_n
4461
n <- min_n
4562
}

R/scales.R

Lines changed: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@
3838
#'
3939
#' @rdname unhcr_scale
4040
#' @export
41-
scale_color_unhcr_c <- function(..., type = "sequential",
42-
palette = 1,
43-
direction = 1,
44-
na.value = "#E9E9E9", guide = "colourbar") {
41+
scale_color_unhcr_c <- function(
42+
...,
43+
type = "sequential",
44+
palette = 1,
45+
direction = 1,
46+
na.value = "#E5E5E5",
47+
guide = "colourbar"
48+
) {
4549
pal <- unhcr_pal_scale(
4650
type = type,
4751
palette = palette,
@@ -59,12 +63,15 @@ scale_color_unhcr_c <- function(..., type = "sequential",
5963

6064
#' @rdname unhcr_scale
6165
#' @export
62-
scale_color_unhcr_d <- function(..., type = "qualitative",
63-
palette = 1,
64-
direction = 1,
65-
nmax = NULL,
66-
order = NULL,
67-
na.value = "#E9E9E9") {
66+
scale_color_unhcr_d <- function(
67+
...,
68+
type = "qualitative",
69+
palette = 1,
70+
direction = 1,
71+
nmax = NULL,
72+
order = NULL,
73+
na.value = "#E5E5E5"
74+
) {
6875
pal <- unhcr_pal_scale(
6976
type = type,
7077
palette = palette,
@@ -83,13 +90,16 @@ scale_color_unhcr_d <- function(..., type = "qualitative",
8390

8491
#' @rdname unhcr_scale
8592
#' @export
86-
scale_color_unhcr_b <- function(..., type = "qualitative",
87-
palette = 1,
88-
direction = 1,
89-
nmax = NULL,
90-
order = NULL,
91-
na.value = "#E9E9E9",
92-
guide = "coloursteps") {
93+
scale_color_unhcr_b <- function(
94+
...,
95+
type = "qualitative",
96+
palette = 1,
97+
direction = 1,
98+
nmax = NULL,
99+
order = NULL,
100+
na.value = "#E5E5E5",
101+
guide = "coloursteps"
102+
) {
93103
pal <- binned_pal(unhcr_pal_scale(
94104
type = type,
95105
palette = palette,
@@ -124,11 +134,14 @@ scale_colour_unhcr_b <- scale_color_unhcr_b
124134

125135
#' @rdname unhcr_scale
126136
#' @export
127-
scale_fill_unhcr_c <- function(..., type = "sequential",
128-
palette = 1,
129-
direction = 1,
130-
na.value = "#E9E9E9",
131-
guide = "colourbar") {
137+
scale_fill_unhcr_c <- function(
138+
...,
139+
type = "sequential",
140+
palette = 1,
141+
direction = 1,
142+
na.value = "#E5E5E5",
143+
guide = "colourbar"
144+
) {
132145
pal <- unhcr_pal_scale(
133146
type = type,
134147
palette = palette,
@@ -146,12 +159,15 @@ scale_fill_unhcr_c <- function(..., type = "sequential",
146159

147160
#' @rdname unhcr_scale
148161
#' @export
149-
scale_fill_unhcr_d <- function(..., type = "qualitative",
150-
palette = 1,
151-
direction = 1,
152-
nmax = NULL,
153-
order = NULL,
154-
na.value = "#E9E9E9") {
162+
scale_fill_unhcr_d <- function(
163+
...,
164+
type = "qualitative",
165+
palette = 1,
166+
direction = 1,
167+
nmax = NULL,
168+
order = NULL,
169+
na.value = "#E5E5E5"
170+
) {
155171
pal <- unhcr_pal_scale(
156172
type = type,
157173
palette = palette,
@@ -170,13 +186,16 @@ scale_fill_unhcr_d <- function(..., type = "qualitative",
170186

171187
#' @rdname unhcr_scale
172188
#' @export
173-
scale_fill_unhcr_b <- function(..., type = "qualitative",
174-
palette = 1,
175-
direction = 1,
176-
nmax = NULL,
177-
order = NULL,
178-
na.value = "#E9E9E9",
179-
guide = "coloursteps") {
189+
scale_fill_unhcr_b <- function(
190+
...,
191+
type = "qualitative",
192+
palette = 1,
193+
direction = 1,
194+
nmax = NULL,
195+
order = NULL,
196+
na.value = "#E5E5E5",
197+
guide = "coloursteps"
198+
) {
180199
pal <- binned_pal(unhcr_pal_scale(
181200
type = type,
182201
palette = palette,
@@ -195,9 +214,13 @@ scale_fill_unhcr_b <- function(..., type = "qualitative",
195214
}
196215

197216
#' @noRd
198-
unhcr_pal_scale <- function(type = "qualitative",
199-
nmax = NULL, order = NULL,
200-
palette = 1, direction = 1) {
217+
unhcr_pal_scale <- function(
218+
type = "qualitative",
219+
nmax = NULL,
220+
order = NULL,
221+
palette = 1,
222+
direction = 1
223+
) {
201224
pal <- unhcr_pal_name(palette, type)
202225

203226
function(n) {
@@ -209,9 +232,12 @@ unhcr_pal_scale <- function(type = "qualitative",
209232
}
210233

211234
if (n > nmax) {
212-
warning("Insufficient values in scale_{color|fill}_unhcr_d. ",
213-
n, " needed but only ",
214-
nmax, " provided.",
235+
warning(
236+
"Insufficient values in scale_{color|fill}_unhcr_d. ",
237+
n,
238+
" needed but only ",
239+
nmax,
240+
" provided.",
215241
call. = FALSE
216242
)
217243
}

R/sysdata.rda

837 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)