forked from mrdwab/koboloadeR
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathkobo_unhcr_style_histo.R
65 lines (57 loc) · 3.26 KB
/
kobo_unhcr_style_histo.R
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
#' @name kobo_unhcr_style_histo
#' @rdname kobo_unhcr_style_histo
#' @title UNHCR ggplot2 theme
#'
#' @description Return ggplot2 styling for histogram
#'
#' @return Return UNHCR Style
#'
#' @author Edouard Legoupil - with inspiration from bbc
#'
#' @examples
#' kobo_unhcr_style_histo()
#'
#' @export kobo_unhcr_style_histo
#'
kobo_unhcr_style_histo <- function() {
font <- "Lato"
ggplot2::theme(
#This sets the font, size, type and colour of text for the chart's title
plot.title = ggplot2::element_text(family = font,
size = 12,
face = "bold",
color = "#222222"),
#This sets the font, size, type and colour of text for the chart's subtitle, as well as setting a margin between the title and the subtitle
plot.subtitle = ggplot2::element_text(family = font,
size = 11,
margin = ggplot2::margin(9,0,9,0)),
#plot.caption = ggplot2::element_blank(),
plot.caption = ggplot2::element_text(family = font,
size = 6,
hjust = 0.92,
margin = ggplot2::margin(t = 0.2, b = 0, unit = "cm"),
color = "#939184"),
#This sets the position and alignment of the legend, removes a title and backround for it and sets the requirements for any text within the legend. The legend may often need some more manual tweaking when it comes to its exact position based on the plot coordinates.
legend.position = "top",
legend.text.align = 0,
legend.background = ggplot2::element_blank(),
legend.title = ggplot2::element_blank(),
legend.key = ggplot2::element_blank(),
legend.text = ggplot2::element_text(family = font, size = 9, color = "#222222"),
#This sets the text font, size and colour for the axis test, as well as setting the margins and removes lines and ticks. In some cases, axis lines and axis ticks are things we would want to have in the chart
axis.title = ggplot2::element_blank(),
axis.text = ggplot2::element_text(family = font, size = 11, color = "#222222"),
axis.text.x = ggplot2::element_text(margin = ggplot2::margin(5, b = 9)),
axis.ticks = ggplot2::element_blank(),
axis.line = ggplot2::element_blank(),
#This removes all minor gridlines and adds major y gridlines. In many cases you will want to change this to remove y gridlines and add x gridlines.
panel.grid.minor = ggplot2::element_blank(),
panel.grid.major.y = ggplot2::element_line(color = "#cbcbcb"),
panel.grid.major.x = ggplot2::element_blank(),
#This sets the panel background as blank, removing the standard grey ggplot background colour from the plot
panel.background = ggplot2::element_blank(),
#This sets the panel background for facet-wrapped plots to white, removing the standard grey ggplot background colour and sets the title size of the facet-wrap title to font size 22
strip.background = ggplot2::element_rect(fill = "white"),
strip.text = ggplot2::element_text(size = 11, hjust = 0)
)
}