seabbs / getTBinR
Showing 4 of 41 files from the diff.
Newly tracked file
R/who_palettes.R created.
Newly tracked file
R/scale_colour_who.R created.
Newly tracked file
R/theme_who.R changed.
Newly tracked file
R/scale_fill_who.R created.
Other files ignored by Codecov
CRAN-RELEASE was deleted.
README.Rmd has changed.
NAMESPACE has changed.
_pkgdown.yml has changed.
README.md has changed.
DESCRIPTION has changed.
NEWS.md has changed.

@@ -0,0 +1,24 @@
Loading
1 +
#' World Health Organization-inspired palettes
2 +
#' 
3 +
#' @param palette A character string. the colours of choice, current options are "main" and "light".
4 +
#' @param reverse Logical, defaults to \code{FALSE}. Should the palette be reversed. 
5 +
#' @param ... Pass additional arguments to \code{colorRampPalette}.
6 +
#' @author Maria Bekker-Nielsen Dunbar
7 +
#' @author Sam Abbott
8 +
#' @export
9 +
#' 
10 +
#' @importFrom grDevices colorRampPalette
11 +
#' @seealso scale_colour_who scale_fill_who
12 +
#' @examples
13 +
#' 
14 +
#' # Set up the main palette but reversed.
15 +
#' who_palettes(palette = "main", reverse = TRUE)
16 +
who_palettes <- function(palette = "main", reverse = FALSE, ...){
17 +
  
18 +
  who_pal <- list("main" = c("#000000", "#EE1A24", "#1591D1"),
19 +
                  "light" = c("#000000", "#FCBEA7", "#BDD5EF"))
20 +
  
21 +
  pal <- who_pal[[palette]]
22 +
  if (reverse) pal <- rev(pal)
23 +
  grDevices::colorRampPalette(pal, ...)
24 +
}

@@ -0,0 +1,38 @@
Loading
1 +
#' Adds World Health Organization-inspired colours to plots
2 +
#' 
3 +
#' 
4 +
#' @description Applies WHO inspired colours for \code{ggplot2} plots. Currently a continuous
5 +
#' palette has not been implemented so the \code{viridis} palettes will be used as a fallback in this situation.
6 +
#' @param discrete Logical, defaults to \code{TRUE}. Should the palette be discrete or continuous.
7 +
#' @param reverse Logical, defaults to \code{FALSE}. Should the colour palette be reversed.
8 +
#' @param ... Pass additional arguments to \code{ggplot2::discrete_scale} or \code{ggplot2::scale_colour_viridis_c}
9 +
#' depending on the \code{discrete} setting.
10 +
#' 
11 +
#' @export
12 +
#' @importFrom ggplot2 discrete_scale scale_fill_viridis_c
13 +
#' @inheritParams who_palettes
14 +
#' @aliases scale_color_who
15 +
#' @seealso scale_colour_who scale_fill_who who_palettes
16 +
#' @author Maria Bekker-Nielsen Dunbar
17 +
#' @author Sam Abbott
18 +
#' @examples 
19 +
#' 
20 +
#' plot_tb_burden_summary(countries = "United Kingdom", compare_all_regions = FALSE,
21 +
#'                        compare_to_region = TRUE, conf = NULL, verbose = FALSE) +
22 +
#' theme_who() +
23 +
#' scale_colour_who(reverse = TRUE)
24 +
scale_colour_who <- function(palette = "main", discrete = TRUE,
25 +
                             reverse = FALSE, ...) {
26 +
  pal <- getTBinR::who_palettes(palette = palette, reverse = reverse)
27 +
  if (isTRUE(discrete)){
28 +
    ggplot2::discrete_scale("colour", paste0("who_", palette), palette = pal, ...)
29 +
  } else {
30 +
    ggplot2::scale_colour_viridis_c(...)
31 +
  }
32 +
}
33 +
34 +
35 +
#' @export
36 +
#' @rdname scale_colour_who
37 +
#' @usage NULL
38 +
scale_color_who <- scale_colour_who

@@ -1,9 +1,17 @@
Loading
1 1
#' World Health Organization-inspired ggplot2 theme
2 2
#' 
3 -
#' @rdname theme_who
4 -
#' @export
5 3
#' 
6 -
#' @seealso [bbplot::bbc_style()]
4 +
#' @description This theme is inspired by that used in the annual global Tuberculosis report. 
5 +
#' See the report [here](https://www.who.int/tb/publications/global_report/en/).
6 +
#' @export
7 +
#' @importFrom ggplot2 element_text theme element_blank margin element_line
8 +
#' @seealso bbplot::bbc_style()
9 +
#' @author Maria Bekker-Nielsen Dunbar
10 +
#' @author Sam Abbott
11 +
#' @examples
12 +
#' 
13 +
#' plot_tb_burden_summary(conf = NULL, verbose = FALSE) +
14 +
#' theme_who()
7 15
theme_who <- function(){
8 16
  font <- "sans" 
9 17
  sz <- 20
@@ -25,13 +33,6 @@
Loading
25 33
                                         colour = "black",
26 34
                                         hjust = 1),
27 35
    
28 -
    # Legend
29 -
    legend.position = "none",
30 -
    legend.text.align = 0,
31 -
    legend.background = ggplot2::element_blank(),
32 -
    legend.title = ggplot2::element_blank(),
33 -
    legend.key = ggplot2::element_blank(),
34 -
    legend.text = ggplot2::element_blank(),
35 36
    
36 37
    # Axis format
37 38
    axis.title = ggplot2::element_text(family = font,
@@ -60,58 +61,3 @@
Loading
60 61
    strip.text = ggplot2::element_text(size = sz + 4, hjust = 0)
61 62
  )
62 63
}
63 -
64 -
who_pal <- list("main" = c("#000000", "#EE1A24", "#1591D1"),
65 -
                "light" = c("#000000", "#FCBEA7", "#BDD5EF"))
66 -
67 -
#' World Health Organization-inspired palettes
68 -
#' 
69 -
#' @param palette The colours of choice, current options are main and light
70 -
#' @param reverse 
71 -
#' 
72 -
#' @export
73 -
#' 
74 -
#' @seealso scale_colour_who scale_fill_who
75 -
who_palettes <- function(palette = "main", reverse = FALSE, ...){
76 -
  pal <- who_pal[[palette]]
77 -
  if (reverse) pal <- rev(pal)
78 -
  colorRampPalette(pal, ...)
79 -
}
80 -
81 -
#' World Health Organization-inspired colours
82 -
#' 
83 -
#' @param palette The colours of choice, current options are main and light
84 -
#' @param reverse 
85 -
#' 
86 -
#' @rdname scale_colour_who
87 -
#' @export
88 -
#' 
89 -
#' @seealso [scale_colour_who() scale_fill_who() who_palettes()]
90 -
scale_colour_who <- function(palette = "main", discrete = TRUE,
91 -
                             reverse = FALSE, ...) {
92 -
  pal <- who_palettes(palette = palette, reverse = reverse)
93 -
  if (isTRUE(discrete)){
94 -
    ggplot2::discrete_scale("colour", paste0("who_", palette), palette = pal, ...)
95 -
  } else {
96 -
    ggplot2::scale_colour_viridis_c(...)
97 -
  }
98 -
}
99 -
100 -
#' @rdname scale_colour_who
101 -
#' @export
102 -
#' @usage NULL
103 -
104 -
scale_color_who <- scale_colour_who
105 -
106 -
#' @rdname scale_colour_who
107 -
#' @export
108 -
109 -
scale_fill_who <- function(palette = "light", discrete = TRUE, reverse = FALSE, ...) {
110 -
  pal <- who_palettes(palette = palette, reverse = reverse)
111 -
  
112 -
  if (isTRUE(discrete)){
113 -
    ggplot2::discrete_scale("fill", paste0("who_", palette), palette = pal, ...)
114 -
  } else {
115 -
    ggplot2::scale_fill_viridis_d(...)
116 -
  }
117 -
}

@@ -0,0 +1,32 @@
Loading
1 +
#' Adds World Health Organization-inspired colours as fills to plots
2 +
#' 
3 +
#' 
4 +
#' @description Applies WHO inspired colours as a fill for \code{ggplot2} plots. Currently a continuous
5 +
#' palette has not been implemented so the \code{viridis} palettes will be used as a fallback in this situation.
6 +
#' 
7 +
#' @export
8 +
#' @importFrom ggplot2 discrete_scale scale_fill_viridis_c
9 +
#' @inheritParams scale_colour_who
10 +
#' @seealso scale_colour_who who_palettes
11 +
#' @author Maria Bekker-Nielsen Dunbar
12 +
#' @author Sam Abbott
13 +
#' 
14 +
#' @examples 
15 +
#' 
16 +
#' 
17 +
#' plot_tb_burden_summary(countries = "United Kingdom", compare_all_regions = FALSE,
18 +
#'                        compare_to_region = TRUE, verbose = FALSE) +
19 +
#' theme_who() +
20 +
#' scale_colour_who(reverse = TRUE) +
21 +
#' scale_fill_who(reverse = TRUE)
22 +
scale_fill_who <- function(palette = "light", discrete = TRUE, 
23 +
                           reverse = FALSE, ...) {
24 +
  
25 +
  pal <- getTBinR::who_palettes(palette = palette, reverse = reverse)
26 +
  
27 +
  if (isTRUE(discrete)){
28 +
    ggplot2::discrete_scale("fill", paste0("who_", palette), palette = pal, ...)
29 +
  } else {
30 +
    ggplot2::scale_fill_viridis_c(...)
31 +
  }
32 +
}
Files Coverage
R 92.93%
Project Totals (17 files) 92.93%

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading