diff --git a/DESCRIPTION b/DESCRIPTION index a0f9e60..ebda723 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,23 +1,29 @@ -Package: visualizeR -Type: Package -Title: What a color! What a viz! -Version: 0.1.4.9000 -Authors@R: c( - person( - 'Noblet', 'Guillaume', - email = 'gnoblet@zaclys.net', - role = c('aut', 'cre') - ) - ) -URL: https://github.com/gnoblet/visualizeR, - https://gnoblet.github.io/visualizeR/ -Maintainer: Guillaume Noblet -Description: It basically provides colors as hex codes, color palettes, and some viz functions (graphs and maps). -Depends: R (>= 4.1.0) -License: GPL (>= 3) -Encoding: UTF-8 -LazyData: true -RoxygenNote: 7.2.0 -Imports: ggplot2, rlang, grDevices, simplevis, glue, scales -Suggests: knitr, sf -VignetteBuilder: knitr +Package: visualizeR +Type: Package +Title: What a color! What a viz! +Version: 0.1.5.9000 +Authors@R: c( + person( + 'Noblet', 'Guillaume', + email = 'gnoblet@zaclys.net', + role = c('aut', 'cre') + ) + ) +URL: https://github.com/gnoblet/visualizeR, + https://gnoblet.github.io/visualizeR/ +Maintainer: Guillaume Noblet +Description: It basically provides colors as hex codes, color palettes, and some viz functions (graphs and maps). +Depends: R (>= 4.1.0) +License: GPL (>= 3) +Encoding: UTF-8 +LazyData: true +RoxygenNote: 7.2.0 +Imports: + ggplot2, + rlang, + grDevices, + glue, + scales, + ggblanket +Suggests: knitr, sf +VignetteBuilder: knitr diff --git a/NEWS.md b/NEWS.md index 0ab98e1..1713d85 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,31 +1,37 @@ -# visualizeR 0.1.4.9000 - -* `hbar()`gains a new boolean argument `reverse` to pass to `pal_reach()` or `pal_agora()`, indicating if the color palette should be reversed or not. - ---- - -# visualizeR 0.1.3.9000 - -* Small change to `hbar()`: removes error arg within `simplevis::gg_hbar()` call. - ---- - -# visualizeR 0.1.2.9000 - -* There was a duplicate `scale_color()` function, which should have been and is now `scale_fill()` - ---- - -# visualizeR 0.1.1.9000 - -* Added two horizontal bar functions: `hbar()`, `hbar_percent()` (#3) -* Added some internals to check for missing columns and bad arguments (#3) -* Modified some `theme_reach()` documentation -* Add `buffer_bbox()` function to produce a buffered bbox, e.g. for use with `tmap` - ---- - -# visualizeR 0.1.0 - -* Added a `NEWS.md` file to track changes to the package -* Initiate repo +# visualizeR 0.1.5.9000 + +* Move from `simplevis` to successor `ggblanket`. + +--- + +# visualizeR 0.1.4.9000 + +* `hbar()` gains a new boolean argument `reverse` to pass to `pal_reach()` or `pal_agora()`, indicating if the color palette should be reversed or not. + +--- + +# visualizeR 0.1.3.9000 + +* Small change to `hbar()`: removes error arg within `simplevis::gg_hbar()` call. + +--- + +# visualizeR 0.1.2.9000 + +* There was a duplicate `scale_color()` function, which should have been and is now `scale_fill()` + +--- + +# visualizeR 0.1.1.9000 + +* Added two horizontal bar functions: `hbar()`, `hbar_percent()` (#3) +* Added some internals to check for missing columns and bad arguments (#3) +* Modified some `theme_reach()` documentation +* Add `buffer_bbox()` function to produce a buffered bbox, e.g. for use with `tmap` + +--- + +# visualizeR 0.1.0 + +* Added a `NEWS.md` file to track changes to the package +* Initiate repo diff --git a/R/hbar.R b/R/hbar.R index eddd99b..1e38cef 100644 --- a/R/hbar.R +++ b/R/hbar.R @@ -1,131 +1,75 @@ #' @title Simple horizontal bar chart #' -#' @description with nice percentage x labels -#' #' @param .tbl Some data #' @param x Some numeric column on the x scale #' @param y Some column on the y scale #' @param group Some grouping categorical column, e.g. administrative areas #' @param initiative Either "reach" or "agora" or "impact" for the color palette +#' @param pal The color palette from the initiative +#' @param width Width. #' @param x_title The x scale title. Default to empty string #' @param y_title The y scale title. Default to empty string #' @param group_title The group legend title. Defaut to NULL #' @param font_family The font family. Default to "Leelawadee" -#' @param stack Should the chart be stacked? Default to "FALSE" (dodge) +#' @param scales_percent Should x_labels be scaled to percentages? Default to TRUE. +#' @param position Should the chart be stacked? Default to dodge #' @param reverse Boolean indicating whether the color palette should be reversed -#' @param ... Other arguments to be passed to "simplevis::gg_hbar" or "simplevis:gg_hbar_col" +#' @param title Plot title. Default to empty string +#' @param subtitle Plot subtitle. Default to empty string +#' @param ... Other arguments to be passed to "ggblanket::gg_col" #' #' @return A horizontal bar chart #' #' @export -hbar_percent <- function(.tbl, x, y, group = NULL, initiative = "reach", x_title = "", y_title = "", group_title = NULL, font_family = "Leelawadee", stack = FALSE, reverse = FALSE, ...){ +hbar <- function(.tbl, x, y, group = NULL, initiative = "reach", pal = "primary", width = 0.5, x_title = "", y_title = "", group_title = NULL, font_family = "Leelawadee", scales_percent = TRUE, position = "dodge", reverse = FALSE, title = "", subtitle = "", ...){ if (!(initiative %in% c("reach", "agora", "impact"))) rlang::abort(c("Wrong `initiative` arg", "*" = paste0("Arg `initiative` cannot be: ", initiative), "i" = "It must be one of 'reach' or 'agora' or 'impact'")) - if (initiative == "reach") main_col <- pal_reach("main", reverse = reverse) + if (initiative == "reach") { + palette <- pal_reach(pal, reverse = reverse) + main_col <- cols_reach("main_grey") - if (initiative == "agora") main_col <- pal_agora("main", reverse = reverse) - - if (initiative == "impact") rlang::abort("IMPACT colors are under development") - - if (is.null(group)) { - hbar <- .tbl |> - simplevis::gg_hbar( - x_var = {{ x }}, - y_var = {{ y }}, - theme = simplevis::gg_theme(font = font_family, pal_title = main_col), - x_title = x_title, - y_title = y_title, - alpha_fill = 1, - pal = main_col, - x_labels = scales::percent, - stack = stack, - ...) - } else { - group_name <- rlang::as_name(rlang::enquo(group)) - if_not_in_stop(.tbl, group_name) - - hbar <- .tbl |> - simplevis::gg_hbar_col( - x_var = {{ x }}, - y_var = {{ y }}, - col_var = {{ group }}, - theme = simplevis::gg_theme(font = font_family, pal_title = main_col), - x_title = x_title, - y_title = y_title, - col_title = group_title, - alpha_fill = 1, - pal = main_col, - x_labels = scales::percent, - stack = stack, - ...) - } - - return(hbar) -} - -#' @title Simple horizontal bar chart -#' -#' @description without any change to the x scale -#' -#' @param .tbl Some data -#' @param x Some numeric column on the x scale -#' @param y Some column on the y scale -#' @param group Some grouping categorical column, e.g. administrative areas -#' @param initiative Either "reach" or "agora" or "impact" for the color palette -#' @param x_title The x scale title. Default to empty string -#' @param y_title The y scale title. Default to empty string -#' @param group_title The group legend title. Defaut to NULL -#' @param font_family The font family. Default to "Leelawadee" -#' @param stack Should the chart be stacked? Default to "FALSE" (dodge) -#' @param reverse Boolean indicating whether the color palette should be reversed -#' @param ... Other arguments to be passed to "simplevis::gg_hbar" or "simplevis:gg_hbar_col" -#' -#' @return A horizontal bar chart -#' -#' @export -hbar <- function(.tbl, x, y, group = NULL, initiative = "reach", x_title = "", y_title = "", group_title = NULL, font_family = "Leelawadee", stack = FALSE, reverse = FALSE,...){ - - - if (!(initiative %in% c("reach", "agora", "impact"))) rlang::abort(c("Wrong `initiative` arg", "*" = paste0("Arg `initiative` cannot be: ", initiative), "i" = "It must be one of 'reach' or 'agora' or 'impact'")) - - if (initiative == "reach") main_col <- pal_reach("main", reverse = reverse) - - if (initiative == "agora") main_col <- pal_agora("main", reverse = reverse) - - if (initiative == "impact") rlang::abort("IMPACT colors are under development") - - if (is.null(group)) { - hbar <- .tbl |> - simplevis::gg_hbar( - x_var = {{ x }}, - y_var = {{ y }}, - theme = simplevis::gg_theme(font = font_family, pal_title = main_col), - x_title = x_title, - y_title = y_title, - alpha_fill = 1, - pal = main_col, - ...) - } else { - group_name <- rlang::as_name(rlang::enquo(group)) - if_not_in_stop(.tbl, group_name) - - hbar <- .tbl |> - simplevis::gg_hbar_col( - x_var = {{ x }}, - y_var = {{ y }}, - col_var = {{ group }}, - theme = simplevis::gg_theme(font = font_family, pal_title = main_col), - x_title = x_title, - y_title = y_title, - col_title = group_title, - alpha_fill = 1, - pal = main_col, - stack = stack, - ...) + if(is.null(palette)) rlang::warn( + c(paste0("There is no palette '", pal, "' for initiative 'reach'. Fallback to ggblanket's default color palette."), + "i" = paste0("Use `pal_reach(show_palettes = T)` to see the list of availabale palettes.") + ) + ) } + if (initiative == "agora") { + palette <- pal_agora(pal, reverse = reverse) + main_col <- cols_agora("main_bordeaux") + + + if(is.null(palette)) rlang::warn( + c(paste0("There is no palette '", pal, "' for initiative 'agora'. Fallback to ggblanket's default color palette."), + "i" = paste0("Use `pal_agora(show_palettes = T)` to see the list of availabale palettes.") + ) + ) + } + + if (initiative == "impact") rlang::warn("IMPACT colors are under development. Fallback to ggblanket's default.") + + hbar <- .tbl |> + ggblanket::gg_col(x = {{ x }}, + y = {{ y }}, + col = {{ group }}, + theme = ggblanket::gg_theme(font = font_family, pal_title = main_col), + x_title = x_title, + y_title = y_title, + col_title = group_title, + alpha_fill = 1, + pal = palette, + width = width, + x_labels = ifelse(scales_percent, scales::percent, NULL), + position = position, + stat = "identity", + title = "", + subtitle = "", + ... + ) + return(hbar) } diff --git a/docs/404.html b/docs/404.html index a8762fd..db84c38 100644 --- a/docs/404.html +++ b/docs/404.html @@ -31,7 +31,7 @@ visualizeR - 0.1.4.9000 + 0.1.5.9000 - - - - - -
-
-
- -
-

with nice percentage x labels

-
- -
-

Usage

-
hbar_percent(
-  .tbl,
-  x,
-  y,
-  group = NULL,
-  initiative = "reach",
-  x_title = "",
-  y_title = "",
-  group_title = NULL,
-  font_family = "Leelawadee",
-  stack = FALSE,
-  reverse = FALSE,
-  ...
-)
-
- -
-

Arguments

-
.tbl
-

Some data

- - -
x
-

Some numeric column on the x scale

- - -
y
-

Some column on the y scale

- - -
group
-

Some grouping categorical column, e.g. administrative areas

- - -
initiative
-

Either "reach" or "agora" or "impact" for the color palette

- - -
x_title
-

The x scale title. Default to empty string

- - -
y_title
-

The y scale title. Default to empty string

- - -
group_title
-

The group legend title. Defaut to NULL

- - -
font_family
-

The font family. Default to "Leelawadee"

- - -
stack
-

Should the chart be stacked? Default to "FALSE" (dodge)

- - -
reverse
-

Boolean indicating whether the color palette should be reversed

- - -
...
-

Other arguments to be passed to "simplevis::gg_hbar" or "simplevis:gg_hbar_col"

- -
-
-

Value

- - -

A horizontal bar chart

-
- -
- - -
- - - -
- - - - - - - diff --git a/docs/reference/if_not_in_stop.html b/docs/reference/if_not_in_stop.html index d6e95f9..1ce45b2 100644 --- a/docs/reference/if_not_in_stop.html +++ b/docs/reference/if_not_in_stop.html @@ -10,7 +10,7 @@ visualizeR - 0.1.4.9000 + 0.1.5.9000