Skip to content

Commit fb42c3c

Browse files
committed
Feat: expand colour/color usage
1 parent 53ea6bf commit fb42c3c

2 files changed

Lines changed: 43 additions & 6 deletions

File tree

R/get_fp_colour.R

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
#' FlatPlot Colour Selection (Multiple Colors)
1+
#' FlatPlot Colour Selection (Multiple Colours)
22
#'
3-
#' @param keys character vector of color names/codes, can be "rl_green", "rl_red", "rl_blue",
4-
#' "rl_yellow", "rl_purple", "rl_orange", "rl_magenta", hex colours, or valid R color names
3+
#' This function takes a character vector of color names/codes and returns a
4+
#' character vector of hex colours. It uses the `get_fp_colour` function to
5+
#' convert each color name/code to its corresponding hex colour. The input can
6+
#' include predefined color names like "rl_green", "rl_red", etc., as well as
7+
#' hex color codes or valid R color names. Use of `get_fp_colors` is valid too.
8+
#'
9+
#' @param keys character vector of color names/codes, can be "rl_green",
10+
#' "rl_red", "rl_blue", "rl_yellow", "rl_purple", "rl_orange", "rl_magenta",
11+
#' "rl_inv", or hex colours, or valid R color names
512
#'
613
#' @return character vector of hex colours
714
#' @export
@@ -13,11 +20,22 @@ get_fp_colours <- function(keys) {
1320
# Apply get_fp_colour to each element in the vector
1421
sapply(keys, get_fp_colour, USE.NAMES = FALSE)
1522
}
23+
#' @rdname get_fp_colours
24+
#' @examples get_fp_colors("rl_green")
25+
#' @export
26+
get_fp_colors <- get_fp_colours
1627

17-
#' FlatPlot Colour Selection (Single Color)
28+
#' FlatPlot Colour Selection (Single Colour)
29+
#'
30+
#' This function takes a single character name/code and returns the
31+
#' corresponding hex colour. It checks if the input is a valid hex colour code
32+
#' or a valid R color name, and if not, it uses a predefined mapping for
33+
#' specific color names like "rl_green", "rl_red", etc. If the input is not
34+
#' valid, it will return NULL. Use of `get_fp_color` is valid too.
1835
#'
1936
#' @param key character name, can be "rl_green", "rl_red", "rl_blue",
20-
#' "rl_yellow", "rl_purple", "rl_orange", "rl_magenta", or a hex colour
37+
#' "rl_yellow", "rl_purple", "rl_orange", "rl_magenta", "rl_inv", or a hex
38+
#' colour, or a valid R color name
2139
#'
2240
#' @return character of hex colour
2341
#' @importFrom grDevices colors
@@ -44,6 +62,11 @@ get_fp_colour <- function(key) {
4462
"rl_yellow" = "#ffc620",
4563
"rl_purple" = "#64318e",
4664
"rl_orange" = "#f59331",
47-
"rl_magenta" = "#da70d6")
65+
"rl_magenta" = "#da70d6",
66+
"rl_inv" = "#ab66f0")
4867
return(colour)
4968
}
69+
#' @rdname get_fp_colour
70+
#' @examples get_fp_color("rl_green")
71+
#' @export
72+
get_fp_color <- get_fp_colour

R/get_sp_colours.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
#' SuperPlot Colour Palette Selection
22
#'
3+
#' This function takes an integer `n` and a character `scheme` and returns a
4+
#' character vector of `n` colours from the specified colour scheme. The
5+
#' function supports four colour schemes from Paul Tol ("tol_bright",
6+
#' "tol_vibrant", "tol_muted", "tol_light") and Color Universal Design ("cud"
7+
#' scheme). If the `scheme` argument is a vector of colours, the function will
8+
#' return the first `n` colours from that vector, repeating the vector if it has
9+
#' fewer than `n` colours. If the `scheme` argument is not a valid colour scheme
10+
#' or a vector of colours, the function will throw an error. Use of
11+
#' `get_sp_colors()` is valid too.
12+
#'
313
#' @param n integer number of colours to return
414
#' @param scheme character name, colour scheme to use
515
#' Choose from one of four palettes from Paul Tol ("tol_bright", "tol_vibrant",
@@ -69,3 +79,7 @@ get_sp_colours <- function(n, scheme) {
6979
}
7080
return(colours)
7181
}
82+
#' @rdname get_sp_colours
83+
#' @examples get_sp_colors(3, "tol_bright")
84+
#' @export
85+
get_sp_colors <- get_sp_colours

0 commit comments

Comments
 (0)