Skip to content

Commit

Permalink
Change name of function
Browse files Browse the repository at this point in the history
  • Loading branch information
caldwellst committed May 10, 2024
1 parent 30f1420 commit 00dadd4
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export(hdx_pal_gray)
export(hdx_pal_mint)
export(hdx_pal_sapphire)
export(hdx_pal_tomato)
export(label_key_figures)
export(label_number_hdx)
export(load_source_sans_3)
export(scale_color_gradient2_hdx)
export(scale_color_gradient_hdx)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Development

- Implement `label_key_figures()` function to improve numeric scales labeling
- Implement `label_number_hdx()` function to improve numeric scales labeling
to match the data visualization guidelines.

# gghdx 0.1.2
Expand Down
22 changes: 11 additions & 11 deletions R/label_key_figures.R → R/label_number_hdx.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Label numeric key figures
#' Label numbers in HDX key figures style
#'
#' Formats numeric vector of key figures in the Centre style, which abbreviates
#' Formats numeric vector in the Centre style for key figures, which abbreviates
#' numbers 1,000 and above to X.YK, 10,000 and above to XYK, 100,000 and above
#' to XYZK, and the same for 1,000,000 and above, replacing the K with an M, and
#' the same for B. Details of the data viz style can be found in the
Expand All @@ -15,7 +15,7 @@
#' Not to be used for percents, which should just use [scales::label_percent()].
#'
#' Designed like the `scales::` family of label functions, the return value of
#' `label_key_figures` is a function, based on the `additional_prefix`. So you
#' `label_number_hdx` is a function, based on the `additional_prefix`. So you
#' should pass it in to `scales_...()` `labels` parameter in the same way as
#' `scales_...()`
#'
Expand Down Expand Up @@ -43,14 +43,14 @@
#'
#' p +
#' scale_x_continuous(
#' labels = label_key_figures("$")
#' labels = label_number_hdx("$")
#' ) +
#' scale_y_continuous(
#' labels = label_key_figures()
#' labels = label_number_hdx()
#' )
#'
#' @export
label_key_figures <- function(additional_prefix = "") {
label_number_hdx <- function(additional_prefix = "") {
if (!is.character(additional_prefix) || length(additional_prefix) > 1) {
stop(
"`additional_prefix` should be a character string of length 1, not a ",
Expand All @@ -60,19 +60,19 @@ label_key_figures <- function(additional_prefix = "") {
)
}

function(x) format_key_figures(x = x, additional_prefix = additional_prefix)
function(x) format_number_hdx(x = x, additional_prefix = additional_prefix)
}

#' Format key figures
#' Format numbers in HDX style
#'
#' Does the formatting found in `label_key_figures`.
#' Does the formatting found in `label_number_hdx`.
#'
#' @inherit label_key_figures params description details
#' @inherit label_number_hdx params description details
#'
#' @param x Numeric vector to format
#'
#' @returns Character vector of formatted strings
format_key_figures <- function(x, additional_prefix) {
format_number_hdx <- function(x, additional_prefix) {
if (!is.numeric(x)) {
stop(
"`x` must be numeric, not class ",
Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ starting from the y-axis.
* `gghdx()` ensures plot for the session use HDX defaults for color and fill
scales, uses `theme_hdx()` for all plots, and applies `scale_color_hdx_...()` and
`scale_fill_hdx_...()`
* `label_key_figures()` supplements the `scales::label_...()` series of functions
to create labels for key figures in the HDX style.
* `label_number_hdx()` supplements the `scales::label_...()` series of functions
to create labels for numbers in the HDX style.

## Installation

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ features. The key functionalities are:
- `gghdx()` ensures plot for the session use HDX defaults for color and
fill scales, uses `theme_hdx()` for all plots, and applies
`scale_color_hdx_...()` and `scale_fill_hdx_...()`
- `label_number_hdx()` supplements the `scales::label_...()` series of
functions to create labels for numbers in the HDX style.

## Installation

Expand Down Expand Up @@ -188,7 +190,7 @@ the visual guide using the theme and color scales in the package.
The inbuilt data `gghdx::df_covid` has aggregated COVID data we can use
to mirror this plot. To make the data start at the y-axis, we can use
`scale_y_continuous_hdx()` which sets `expand = c(0, 0)` by default, and
the `label_key_figures()` function to create custom labels.
the `label_number_hdx()` function to create custom labels.

``` r
p_blue <- ggplot(
Expand All @@ -204,7 +206,7 @@ p_blue <- ggplot(
fill = hdx_hex("sapphire-hdx") # use sapphire for fill
) +
scale_y_continuous_hdx(
labels = label_key_figures()
labels = label_number_hdx()
) +
scale_x_date(
date_breaks = "1 month",
Expand Down
Binary file modified man/figures/README-extrafont-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-gghdx-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-intro-hdx-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-intro-plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-intro-ramp-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions man/format_key_figures.Rd → man/format_number_hdx.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions man/label_key_figures.Rd → man/label_number_hdx.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vignettes/gghdx.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ knitr::include_graphics(
The inbuilt data `gghdx::df_covid` has aggregated COVID data we can use to
mirror this plot. To make the data start at the y-axis, we can use
`scale_y_continuous_hdx()` which sets `expand = c(0, 0)` by default, and the
`label_key_figures()` function to create custom labels.
`label_number_hdx()` function to create custom labels.

```{r covid-match, fig.height = 5, fig.width = 6, out.width = "45%", fig.show = "hold", fig.align = "default"}
p_blue <- ggplot(
Expand All @@ -167,7 +167,7 @@ p_blue <- ggplot(
fill = hdx_hex("sapphire-hdx") # use sapphire for fill
) +
scale_y_continuous_hdx(
labels = label_key_figures()
labels = label_number_hdx()
) +
scale_x_date(
date_breaks = "1 month",
Expand Down

0 comments on commit 00dadd4

Please sign in to comment.