diff --git a/DESCRIPTION b/DESCRIPTION index ebda723..b67d4c9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: visualizeR Type: Package Title: What a color! What a viz! -Version: 0.1.5.9000 +Version: 0.1.6.9000 Authors@R: c( person( 'Noblet', 'Guillaume', @@ -17,7 +17,7 @@ Depends: R (>= 4.1.0) License: GPL (>= 3) Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.0 +RoxygenNote: 7.2.1 Imports: ggplot2, rlang, diff --git a/NEWS.md b/NEWS.md index 1713d85..982f50f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# visualizeR 0.1.6.9000 + +* IMPACT colors and palettes are added: function `cols_impact()` `pal_impact()`. +* Color palettes from REACH are added (2 to 7 continuous palettes) ; see updated `cols_reach()` and `pal_reach()`. + +--- + # visualizeR 0.1.5.9000 * Move from `simplevis` to successor `ggblanket`. diff --git a/R/cols_impact.R b/R/cols_impact.R new file mode 100644 index 0000000..c74bdaf --- /dev/null +++ b/R/cols_impact.R @@ -0,0 +1,30 @@ +#' @title Function to extract IMPACT colors as hex codes +#' +#' @param ... Character names of reach colors. If NULL returns all colors +#' @param unnamed Should the output vector be unnamed? Default to `TRUE` +#' +#' @return An hex code or hex codes named or unnamed +#' +#' @details This function needs to be modified to add colors +#' +#' @export +cols_impact <- function(..., unnamed = TRUE) { + cols <- c(...) + + colors_impact <- c(white = "#FFFFFF", + black = "#000000", + main_blue = "#315975", + main_gray = "#58585A") + + if (is.null(cols)) { + cols_to_return <- colors_impact + } else { + cols_to_return <- colors_impact[cols] + } + + if(unnamed){ + cols_to_return <- unname(cols_to_return) + } + + return(cols_to_return) +} diff --git a/R/cols_reach.R b/R/cols_reach.R index 317948d..2957e57 100644 --- a/R/cols_reach.R +++ b/R/cols_reach.R @@ -11,49 +11,148 @@ cols_reach <- function(..., unnamed = TRUE) { cols <- c(...) - colors_reach <- c(white = "#FFFFFF", - black = "#000000", - main_grey = "#58585A", - main_red = "#EE5859", - main_lt_grey = "#C7C8CA", - main_beige = "#D2CBB8", - iroise_1 = "#DFECEF", - iroise_2 = "#B1D7E0", - iroise_3 = "#699DA3", - iroise_4 = "#236A7A", - iroise_5 = "#0C3842", - red_main_1 = "#AE2829", - red_main_2 = "#D05E5F", - red_main_3 = "#DB9797", - red_main_4 = "#EBC7C8", - red_main_5 = "#FAF2F2", - red_alt_1 = "#792a2e", - red_alt_2 = "#c0474a", - red_alt_3 = "#ee5859", - red_alt_4 = "#f49695", - red_alt_5 = "#f8d6d6", - red_alt_na = "#f8f4f4", - lt_grey_1 = "#C6C6C6", - lt_grey_2 = "#818183", - grey3 = "#E3E3E3", - dk_grey = "#464647", - two_dots_1 = "#706441", - two_dots_2 = "#56b4e9", - two_dots_flashy_1 = "gold1", - two_dots_flashy_2 = "blue2", - three_dots_1 = "aquamarine2", - three_dots_2 = "cornflowerbluer", - three_dots_3 = "brown1", - orpink = "#f8aa9b", - pink = "#f5a6a7", - lt_pink = "#F9C6C7", - hot_pink = "#ef6d6f", - mddk_red = "#bf4749", - dk_red = "#782c2e", - orange = "#F69E61", - lt_green = "#B0CFAC", - green = "#84A181", - dk_green = "#526450") + colors_reach <- c( + white = "#FFFFFF", + black = "#000000", + main_grey = "#58585A", + main_red = "#EE5859", + main_lt_grey = "#C7C8CA", + main_beige = "#D2CBB8", + iroise_1 = "#DFECEF", + iroise_2 = "#B1D7E0", + iroise_3 = "#699DA3", + iroise_4 = "#236A7A", + iroise_5 = "#0C3842", + red_main_1 = "#AE2829", + red_main_2 = "#D05E5F", + red_main_3 = "#DB9797", + red_main_4 = "#EBC7C8", + red_main_5 = "#FAF2F2", + red_alt_1 = "#792a2e", + red_alt_2 = "#c0474a", + red_alt_3 = "#ee5859", + red_alt_4 = "#f49695", + red_alt_5 = "#f8d6d6", + red_alt_na = "#f8f4f4", + lt_grey_1 = "#C6C6C6", + lt_grey_2 = "#818183", + grey3 = "#E3E3E3", + dk_grey = "#464647", + two_dots_1 = "#706441", + two_dots_2 = "#56b4e9", + two_dots_flashy_1 = "gold1", + two_dots_flashy_2 = "blue2", + three_dots_1 = "aquamarine2", + three_dots_2 = "cornflowerbluer", + three_dots_3 = "brown1", + orpink = "#f8aa9b", + pink = "#f5a6a7", + lt_pink = "#F9C6C7", + hot_pink = "#ef6d6f", + mddk_red = "#bf4749", + dk_red = "#782c2e", + orange = "#F69E61", + lt_green = "#B0CFAC", + green = "#84A181", + dk_green = "#526450", + red_less_4_1 = "#f6e3e3", + red_less_4_2 = "#f3b5b6", + red_less_4_3 = "#ee5a59", + red_less_4_4 = "#9d393c", + red_5_1 = "#f6e3e3", + red_5_2 = "#f3b5b6", + red_5_3 = "#ee5a59", + red_5_4 = "#c0474a", + red_5_5 = "#792a2e", + red_less_7_1 = "#f8f4f4", + red_less_7_2 = "#f8d6d6", + red_less_7_3 = "#f49695", + red_less_7_4 = "#ee5a59", + red_less_7_5 = "#c0474a", + red_less_7_6 = "#792a2e", + red_less_7_7 = "#471119", + green_2_1 = "#cce5c9", + green_2_2 = "#55a065", + green_3_1 = "#e6f2e0", + green_3_2 = "#7ebf85", + green_3_3 = "#2d8246", + green_4_1 = "#e6f2e1", + green_4_2 = "#b0d3ab", + green_4_3 = "#4bab5e", + green_4_4 = "#0c592e", + green_5_1 = "#e6f2e1", + green_5_2 = "#b0d3ab", + green_5_3 = "#6bb26a", + green_5_4 = "#229346", + green_5_5 = "#0c592e", + green_6_1 = "#e6f2e0", + green_6_2 = "#b0d3ab", + green_6_3 = "#75c376", + green_6_4 = "#086d38", + green_6_5 = "#0c592e", + green_6_6 = "#0d4420", + green_7_1 = "#fafafa", + green_7_2 = "#e6f2e0", + green_7_3 = "#b0d3ab", + green_7_4 = "#75c376", + green_7_5 = "#40ab5d", + green_7_6 = "#086d38", + green_7_7 = "#0d4420", + artichoke_2_1 = "#b6c8b1", + artichoke_2_2 = "#53755f", + artichoke_3_1 = "#e4f1db", + artichoke_3_2 = "#89a087", + artichoke_3_3 = "#455843", + artichoke_4_1 = "#e4f1db", + artichoke_4_2 = "#b5ceb2", + artichoke_4_3 = "#89a087", + artichoke_4_4 = "#465944", + artichoke_5_1 = "#e4f1db", + artichoke_5_2 = "#b5ceb2", + artichoke_5_3 = "#89a087", + artichoke_5_4 = "#60755f", + artichoke_5_5 = "#465944", + artichoke_6_1 = "#fafafa", + artichoke_6_2 = "#e4f1db", + artichoke_6_3 = "#b5ceb2", + artichoke_6_4 = "#89a087", + artichoke_6_5 = "#60755f", + artichoke_6_6 = "#455843", + artichoke_7_1 = "#fafafa", + artichoke_7_2 = "#e4f1db", + artichoke_7_3 = "#b5ceb2", + artichoke_7_4 = "#9fb89c", + artichoke_7_5 = "#89a087", + artichoke_7_6 = "#60755f", + artichoke_7_7 = "#455843", + blue_2_1 = "#7cb6c4", + blue_2_2 = "#286877 ", + blue_3_1 = "#b9d7de", + blue_3_2 = "#5ca4b4", + blue_3_3 = "#286877", + blue_4_1 = "#dfecef", + blue_4_2 = "#8fc1cc", + blue_4_3 = "#3f96aa", + blue_4_4 = "#286877", + blue_5_1 = "#dfecef", + blue_5_2 = "#8fc1cc", + blue_5_3 = "#3f96aa", + blue_5_4 = "#256a7a", + blue_5_5 = "#0c3842", + blue_6_1 = "#f4fbfe", + blue_6_2 = "#cfe4e9", + blue_6_3 = "#77b2bf", + blue_6_4 = "#4096aa", + blue_6_5 = "#256a7a", + blue_6_6 = "#0c3842", + blue_7_1 = "#f4fbfe", + blue_7_2 = "#b3d5de", + blue_7_3 = "#77b2bf", + blue_7_4 = "#4096aa", + blue_7_5 = "#27768a", + blue_7_6 = "#0c596b", + blue_7_7 = "#0c3842" + ) if (is.null(cols)) { cols_to_return <- colors_reach @@ -61,7 +160,7 @@ cols_reach <- function(..., unnamed = TRUE) { cols_to_return <- colors_reach[cols] } - if(unnamed){ + if (unnamed) { cols_to_return <- unname(cols_to_return) } diff --git a/R/pal_impact.R b/R/pal_impact.R new file mode 100644 index 0000000..ff9b561 --- /dev/null +++ b/R/pal_impact.R @@ -0,0 +1,34 @@ +#' @title Return function to interpolate an IMPACT color palette +#' +#' @param palette Character name of a palette in IMPACT palettes +#' @param reverse Boolean indicating whether the palette should be reversed +#' @param color_ramp_palette Should the output be a `grDevices::colorRampPalette` function or a vector of hex codes? Default to the former with `TRUE` +#' @param show_palettes Should the ouput be the set of palettes names to pick from? Default to `FALSE` +#' @param ... Additional arguments to pass to colorRampPalette() +#' +#' @return A color palette +#' +#' @export +pal_impact <- function(palette = "main", reverse = FALSE, color_ramp_palette = FALSE, show_palettes = FALSE, ...) { + + + palettes_impact <- list( + `main` = cols_impact("black", "white", "main_blue", "main_grey"), + `primary` = cols_impact("black", "white"), + `secondary` = cols_impact("main_blue", "main_grey") + ) + + if (show_palettes) return(names(palettes_impact)) + + pal <- palettes_impact[[palette]] + + if (reverse) pal <- rev(pal) + + if (color_ramp_palette) { + rlang::check_installed("grDevices", reason = "Package \"grDevices\" needed for `pal_impact()` woth 'color_ramp_palette' set to `TRUE` to work. Please install it.") + + pal <- grDevices::colorRampPalette(pal, ...) + } + + return(pal) +} diff --git a/R/pal_reach.R b/R/pal_reach.R index 4fd58bf..e3332b8 100644 --- a/R/pal_reach.R +++ b/R/pal_reach.R @@ -19,9 +19,36 @@ pal_reach <- function(palette = "main", reverse = FALSE, color_ramp_palette = FA `two_dots` = cols_reach("two_dots_1", "two_dots_2"), `two_dots_flashy` = cols_reach("two_dots_flashy_1", "two_dots_flashy_2"), `red_main` = cols_reach("red_main_1", "red_main_2", "red_main_3", "red_main_4", "red_main_5"), + `red_main_5` = cols_reach("red_main_1", "red_main_2", "red_main_3", "red_main_4", "red_main_5"), `red_alt` = cols_reach("red_alt_1", "red_alt_2", "red_alt_3", "red_alt_4", "red_alt_5"), + `red_alt_5` = cols_reach("red_alt_1", "red_alt_2", "red_alt_3", "red_alt_4", "red_alt_5"), `iroise` = cols_reach("iroise_1", "iroise_2", "iroise_3", "iroise_4", "iroise_5"), - `discrete_6` = cols_reach("dk_grey", "red_main_1", "main_beige", "red_main_2", "lt_grey_2", "red_4") + `iroise_5` = cols_reach("iroise_1", "iroise_2", "iroise_3", "iroise_4", "iroise_5"), + `discrete_6` = cols_reach("dk_grey", "red_main_1", "main_beige", "red_main_2", "lt_grey_2", "red_4"), + `red_2` = cols_reach("red_less_4_1", "red_less_4_3"), + `red_3` = cols_reach("red_less_4_1", "red_less_2", "red_less_4_3"), + `red_4` = cols_reach("red_less_4_1", "red_less_2", "red_less_4_3", "red_less_4_4"), + `red_5` = cols_reach("red_5_1", "red_5_2", "red_5_3", "red_5_4", "red_5_5"), + `red_6` = cols_reach("red_less_7_1", "red_less_2", "red_less_7_3", "red_less_7_4", "red_less_7_5", "red_less_7_6"), + `red_7` = cols_reach("red_less_7_1", "red_less_7_2", "red_less_7_3", "red_less_7_4", "red_less_7_5", "red_less_7_6", "red_less_7_7"), + `green_2` = cols_reach("green_2_1", "green_2_2"), + `green_3` = cols_reach("green_3_1", "green_3_2", "green_3_3"), + `green_4` = cols_reach("green_4_1", "green_4_2", "green_4_3", "green_4_4"), + `green_5` = cols_reach("green_5_1", "green_5_2", "green_5_3", "green_5_4", "green_5_5"), + `green_6` = cols_reach("green_6_1", "green_6_2", "green_6_3", "green_6_4", "green_6_5", "green_6_6"), + `green_7` = cols_reach("green_7_1", "green_7_2", "green_7_3", "green_7_4", "green_7_5", "green_7_6", "green_7_7"), + `artichoke_2` = cols_reach("artichoke_2_1", "artichoke_2_2"), + `artichoke_3` = cols_reach("artichoke_3_1", "artichoke_3_2", "artichoke_3_3"), + `artichoke_4` = cols_reach("artichoke_4_1", "artichoke_4_2", "artichoke_4_3", "artichoke_4_4"), + `artichoke_5` = cols_reach("artichoke_5_1", "artichoke_5_2", "artichoke_5_3", "artichoke_5_4", "artichoke_5_5"), + `artichoke_6` = cols_reach("artichoke_6_1", "artichoke_6_2", "artichoke_6_3", "artichoke_6_4", "artichoke_6_5", "artichoke_6_6"), + `artichoke_7` = cols_reach("artichoke_7_1", "artichoke_7_2", "artichoke_7_3", "artichoke_7_4", "artichoke_7_5", "artichoke_7_6", "artichoke_7_7"), + `blue_2` = cols_reach("blue_2_1", "blue_2_2"), + `blue_3` = cols_reach("blue_3_1", "blue_3_2", "blue_3_3"), + `blue_4` = cols_reach("blue_4_1", "blue_4_2", "blue_4_3", "blue_4_4"), + `blue_5` = cols_reach("blue_5_1", "blue_5_2", "blue_5_3", "blue_5_4", "blue_5_5"), + `blue_6` = cols_reach("blue_6_1", "blue_6_2", "blue_6_3", "blue_6_4", "blue_6_5", "blue_6_6"), + `blue_7` = cols_reach("blue_7_1", "blue_7_2", "blue_7_3", "blue_7_4", "blue_7_5", "blue_7_6", "blue_7_7") ) if (show_palettes) return(names(palettes_reach)) diff --git a/README.Rmd b/README.Rmd index 52638b5..0002369 100644 --- a/README.Rmd +++ b/README.Rmd @@ -37,8 +37,9 @@ devtools::install_github("gnoblet/visualizeR", build_vignettes = TRUE) Roadmap is as follows: -- [ ] Add IMPACT's colors -- [ ] Add all color palettes from the internal documentation +- [X] Add IMPACT's colors +- [X] Add all color palettes from the internal documentation +- [ ] There remains to be added more-than-7-color palettes and black color palettes - [ ] Add new types of visualization (e.g. dumbbell plot) - [ ] Use examples - [ ] Add some ease-map functions diff --git a/README.md b/README.md index f1cc152..6693b4d 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,10 @@ devtools::install_github("gnoblet/visualizeR", build_vignettes = TRUE) Roadmap is as follows: -- [ ] Add IMPACT’s colors -- [ ] Add all color palettes from the internal documentation +- [x] Add IMPACT’s colors +- [x] Add all color palettes from the internal documentation +- [ ] There remains to be added more-than-7-color palettes and black + color palettes - [ ] Add new types of visualization (e.g. dumbbell plot) - [ ] Use examples - [ ] Add some ease-map functions diff --git a/docs/404.html b/docs/404.html index db84c38..8e4f506 100644 --- a/docs/404.html +++ b/docs/404.html @@ -13,8 +13,8 @@ - - + + @@ -31,7 +31,7 @@ visualizeR - 0.1.5.9000 + 0.1.6.9000 + + + + + +
+
+
+ +
+

Function to extract IMPACT colors as hex codes

+
+ +
+

Usage

+
cols_impact(..., unnamed = TRUE)
+
+ +
+

Arguments

+
...
+

Character names of reach colors. If NULL returns all colors

+ + +
unnamed
+

Should the output vector be unnamed? Default to `TRUE`

+ +
+
+

Value

+ + +

An hex code or hex codes named or unnamed

+
+
+

Details

+

This function needs to be modified to add colors

+
+ +
+ + +
+ + + + + + + diff --git a/docs/reference/cols_reach.html b/docs/reference/cols_reach.html index 76ef7c9..f2138b2 100644 --- a/docs/reference/cols_reach.html +++ b/docs/reference/cols_reach.html @@ -1,5 +1,5 @@ -Function to extract REACH colors as hex codes — cols_reach • visualizeRFunction to extract REACH colors as hex codes — cols_reach • visualizeR @@ -10,7 +10,7 @@ visualizeR - 0.1.5.9000 + 0.1.6.9000 + + + + + +
+
+
+ +
+

Return function to interpolate an IMPACT color palette

+
+ +
+

Usage

+
pal_impact(
+  palette = "main",
+  reverse = FALSE,
+  color_ramp_palette = FALSE,
+  show_palettes = FALSE,
+  ...
+)
+
+ +
+

Arguments

+
palette
+

Character name of a palette in IMPACT palettes

+ + +
reverse
+

Boolean indicating whether the palette should be reversed

+ + +
color_ramp_palette
+

Should the output be a `grDevices::colorRampPalette` function or a vector of hex codes? Default to the former with `TRUE`

+ + +
show_palettes
+

Should the ouput be the set of palettes names to pick from? Default to `FALSE`

+ + +
...
+

Additional arguments to pass to colorRampPalette()

+ +
+
+

Value

+ + +

A color palette

+
+ +
+ + +
+ + + + + + + diff --git a/docs/reference/pal_reach.html b/docs/reference/pal_reach.html index 81265fb..49360c4 100644 --- a/docs/reference/pal_reach.html +++ b/docs/reference/pal_reach.html @@ -1,5 +1,5 @@ -Return function to interpolate a REACH color palette — pal_reach • visualizeRReturn function to interpolate a REACH color palette — pal_reach • visualizeR @@ -10,7 +10,7 @@ visualizeR - 0.1.5.9000 + 0.1.6.9000