Skip to content

Commit

Permalink
Fix NA transparent (#27)
Browse files Browse the repository at this point in the history
* Make continuous scales have transparent values

* Update NEWS.md

* Moving to latest GitHub Actions CMD check workflow in devtools

* Deal with scale_name issues based on ggplot version
  • Loading branch information
caldwellst authored May 14, 2024
1 parent 9831e57 commit 9564d64
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 80 deletions.
25 changes: 8 additions & 17 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
#
# NOTE: This workflow is overkill for most R packages and
# check-standard.yaml is likely a better choice.
# usethis::use_github_action("check-standard") will install it.
on:
push:
branches: [main, master]
Expand All @@ -12,6 +8,8 @@ on:

name: R-CMD-check

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
Expand All @@ -22,26 +20,18 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}

- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}

# Use older ubuntu to maximise backward compatibility
- {os: ubuntu-18.04, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-18.04, r: 'release'}
- {os: ubuntu-18.04, r: 'oldrel-1'}
- {os: ubuntu-18.04, r: 'oldrel-2'}
- {os: ubuntu-18.04, r: 'oldrel-3'}
- {os: ubuntu-18.04, r: 'oldrel-4'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -59,3 +49,4 @@ jobs:
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Imports:
dplyr,
ggplot2,
ggthemes,
lifecycle,
magrittr,
purrr,
rlang,
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

- Implement `label_number_hdx()` function to improve numeric scales labeling
to match the data visualization guidelines.
- Switch develop continous `NA` fill value to be `"transparent"` so it appears
better when plotting continuous rasters.
- Check installed `{ggplot2}` version to pass the `scale_name` argument to remove
warnings and errors.

# gghdx 0.1.2

Expand Down
90 changes: 60 additions & 30 deletions R/scale_hdx.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@
#' along with other styling.
#'
#' @export
scale_color_hdx_discrete <- function(...) {
scale_color_hdx_discrete <- function(na.value = hdx_hex("gray-light"), ...) {
ggplot2::discrete_scale(
aesthetics = "colour",
scale_name = scale_name(),
palette = hdx_pal_discrete(),
na.value = hdx_hex("gray-light"),
na.value = na.value,
...
)
}
Expand All @@ -66,11 +67,12 @@ scale_colour_hdx_discrete <- scale_color_hdx_discrete

#' @rdname scale_hdx
#' @export
scale_color_hdx_gray <- function(...) {
scale_color_hdx_gray <- function(na.value = hdx_hex("tomato-hdx"), ...) {
ggplot2::discrete_scale(
aesthetics = "colour",
scale_name = scale_name(),
palette = hdx_pal_gray(),
na.value = hdx_hex("tomato-hdx"),
na.value = na.value,
...
)
}
Expand All @@ -89,11 +91,12 @@ scale_color_hdx_grey <- scale_color_hdx_gray

#' @rdname scale_hdx
#' @export
scale_color_hdx_mint <- function(...) {
scale_color_hdx_mint <- function(na.value = hdx_hex("gray-light"), ...) {
ggplot2::discrete_scale(
aesthetics = "colour",
scale_name = scale_name(),
palette = hdx_pal_mint(),
na.value = hdx_hex("gray-light"),
na.value = na.value,
...
)
}
Expand All @@ -104,11 +107,12 @@ scale_colour_hdx_mint <- scale_color_hdx_mint

#' @rdname scale_hdx
#' @export
scale_color_hdx_sapphire <- function(...) {
scale_color_hdx_sapphire <- function(na.value = hdx_hex("gray-light"), ...) {
ggplot2::discrete_scale(
aesthetic = "colour",
scale_name = scale_name(),
palette = hdx_pal_sapphire(),
na.value = hdx_hex("gray-light"),
na.value = na.value,
...
)
}
Expand All @@ -119,11 +123,12 @@ scale_colour_hdx_sapphire <- scale_color_hdx_sapphire

#' @rdname scale_hdx
#' @export
scale_color_hdx_tomato <- function(...) {
scale_color_hdx_tomato <- function(na.value = hdx_hex("gray-light"), ...) {
ggplot2::discrete_scale(
aesthetics = "colour",
scale_name = scale_name(),
palette = hdx_pal_tomato(),
na.value = hdx_hex("gray-light"),
na.value = na.value,
...
)
}
Expand All @@ -134,22 +139,24 @@ scale_colour_hdx_tomato <- scale_color_hdx_tomato

#' @rdname scale_hdx
#' @export
scale_fill_hdx_discrete <- function(...) {
scale_fill_hdx_discrete <- function(na.value = hdx_hex("gray-light"), ...) {
ggplot2::discrete_scale(
aesthetics = "fill",
scale_name = scale_name(),
palette = hdx_pal_discrete(),
na.value = hdx_hex("gray-light"),
na.value = na.value,
...
)
}

#' @rdname scale_hdx
#' @export
scale_fill_hdx_gray <- function(...) {
scale_fill_hdx_gray <- function(na.value = hdx_hex("tomato-hdx"), ...) {
ggplot2::discrete_scale(
aesthetics = "fill",
scale_name = scale_name(),
palette = hdx_pal_gray(),
na.value = hdx_hex("tomato-hdx"),
na.value = na.value,
...
)
}
Expand All @@ -160,103 +167,116 @@ scale_fill_hdx_grey <- scale_fill_hdx_gray

#' @rdname scale_hdx
#' @export
scale_fill_hdx_mint <- function(...) {
scale_fill_hdx_mint <- function(na.value = hdx_hex("gray-light"), ...) {
ggplot2::discrete_scale(
aesthetics = "fill",
scale_name = scale_name(),
palette = hdx_pal_mint(),
na.value = hdx_hex("gray-light"),
na.value = na.value,
...
)
}

#' @rdname scale_hdx
#' @export
scale_fill_hdx_sapphire <- function(...) {
scale_fill_hdx_sapphire <- function(na.value = hdx_hex("gray-light"), ...) {
ggplot2::discrete_scale(
aesthetics = "fill",
scale_name = scale_name(),
palette = hdx_pal_sapphire(),
na.value = hdx_hex("gray-light"),
na.value = na.value,
...
)
}

#' @rdname scale_hdx
#' @export
scale_fill_hdx_tomato <- function(...) {
scale_fill_hdx_tomato <- function(na.value = hdx_hex("gray-light"), ...) {
ggplot2::discrete_scale(
aesthetics = "fill",
scale_name = scale_name(),
palette = hdx_pal_tomato(),
na.value = hdx_hex("gray-light"),
na.value = na.value,
...
)
}

#' @rdname scale_hdx
#' @export
scale_fill_gradient_hdx <- function(...) {
scale_fill_gradient_hdx <- function(na.value = "transparent", ...) {
ggplot2::continuous_scale(
aesthetics = "fill",
scale_name = scale_name(),
palette = scales::seq_gradient_pal(
low = hdx_hex("tomato-hdx"),
high = hdx_hex("sapphire-hdx")
),
guide = "colorbar",
na.value = na.value,
...
)
}

#' @rdname scale_hdx
#' @export
scale_fill_gradient_hdx_sapphire <- function(...) {
scale_fill_gradient_hdx_sapphire <- function(na.value = "transparent", ...) {
ggplot2::continuous_scale(
aesthetics = "fill",
scale_name = scale_name(),
palette = scales::seq_gradient_pal(
low = "white",
high = hdx_hex("sapphire-hdx")
),
guide = "colorbar",
na.value = na.value,
...
)
}

#' @rdname scale_hdx
#' @export
scale_fill_gradient_hdx_mint <- function(...) {
scale_fill_gradient_hdx_mint <- function(na.value = "transparent", ...) {
ggplot2::continuous_scale(
aesthetics = "fill",
scale_name = scale_name(),
palette = scales::seq_gradient_pal(
low = "white",
high = hdx_hex("mint-hdx")
),
guide = "colorbar",
na.value = na.value,
...
)
}

#' @rdname scale_hdx
#' @export
scale_fill_gradient_hdx_tomato <- function(...) {
scale_fill_gradient_hdx_tomato <- function(na.value = "transparent", ...) {
ggplot2::continuous_scale(
aesthetics = "fill",
scale_name = scale_name(),
palette = scales::seq_gradient_pal(
low = "white",
high = hdx_hex("tomato-hdx")
),
guide = "colorbar",
na.value = na.value,
...
)
}

#' @rdname scale_hdx
#' @export
scale_color_gradient_hdx <- function(...) {
scale_color_gradient_hdx <- function(na.value = "transparent", ...) {
ggplot2::continuous_scale(
aesthetics = "color",
scale_name = scale_name(),
palette = scales::seq_gradient_pal(
low = hdx_hex("tomato-hdx"),
high = hdx_hex("sapphire-hdx")
),
guide = "colorbar",
na.value = na.value,
...
)
}
Expand All @@ -267,14 +287,16 @@ scale_colour_gradient_hdx <- scale_color_gradient_hdx

#' @rdname scale_hdx
#' @export
scale_color_gradient_hdx_sapphire <- function(...) {
scale_color_gradient_hdx_sapphire <- function(na.value = "transparent", ...) {
ggplot2::continuous_scale(
aesthetics = "color",
scale_name = scale_name(),
palette = scales::seq_gradient_pal(
low = "white",
high = hdx_hex("sapphire-hdx")
),
guide = "colorbar",
na.value = na.value,
...
)
}
Expand All @@ -285,14 +307,16 @@ scale_colour_gradient_hdx_sapphire <- scale_color_gradient_hdx_sapphire

#' @rdname scale_hdx
#' @export
scale_color_gradient_hdx_mint <- function(...) {
scale_color_gradient_hdx_mint <- function(na.value = "transparent", ...) {
ggplot2::continuous_scale(
aesthetics = "color",
scale_name = scale_name(),
palette = scales::seq_gradient_pal(
low = "white",
high = hdx_hex("mint-hdx")
),
guide = "colorbar",
na.value = na.value,
...
)
}
Expand All @@ -303,14 +327,16 @@ scale_colour_gradient_hdx_mint <- scale_color_gradient_hdx_mint

#' @rdname scale_hdx
#' @export
scale_color_gradient_hdx_tomato <- function(...) {
scale_color_gradient_hdx_tomato <- function(na.value = "transparent", ...) {
ggplot2::continuous_scale(
aesthetics = "color",
scale_name = scale_name(),
palette = scales::seq_gradient_pal(
low = "white",
high = hdx_hex("tomato-hdx")
),
guide = "colorbar",
na.value = na.value,
...
)
}
Expand All @@ -321,15 +347,17 @@ scale_colour_gradient_hdx_tomato <- scale_color_gradient_hdx_tomato

#' @rdname scale_hdx
#' @export
scale_color_gradient2_hdx <- function(...) {
scale_color_gradient2_hdx <- function(na.value = "transparent", ...) {
ggplot2::continuous_scale(
aesthetics = "color",
scale_name = scale_name(),
palette = scales::div_gradient_pal(
low = hdx_hex("tomato-hdx"),
mid = hdx_hex("gray-white"),
high = hdx_hex("sapphire-hdx")
),
guide = "colorbar",
na.value = na.value,
...
)
}
Expand All @@ -340,15 +368,17 @@ scale_colour_gradient2_hdx <- scale_color_gradient2_hdx

#' @rdname scale_hdx
#' @export
scale_fill_gradient2_hdx <- function(...) {
scale_fill_gradient2_hdx <- function(na.value = "transparent", ...) {
ggplot2::continuous_scale(
aesthetics = "fill",
scale_name = scale_name(),
palette = scales::div_gradient_pal(
low = hdx_hex("tomato-hdx"),
mid = hdx_hex("gray-white"),
high = hdx_hex("sapphire-hdx")
),
guide = "colorbar",
na.value = na.value,
...
)
}
Loading

0 comments on commit 9564d64

Please sign in to comment.