Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/teunbrand/ggh4x
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Mar 25, 2024
2 parents ea64b81 + 22d23db commit 80c6491
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggh4x (development version)

* `help_secondary()` has a new `na.rm` argument (#146, thanks @jrmuirhead!)

# ggh4x 0.2.8

This is a small release fixing a NOTE by request. In addition, there are two
Expand Down
20 changes: 12 additions & 8 deletions R/help_secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#' \item{`"sortfit"`}{Sorts the both `primary` and `secondary` independently
#' before passing these on to the `"fit"` method.}
#' }
#' @param na.rm A `logical(1)`: whether to remove missing values (`TRUE`) or
#' propagate missing values (`FALSE`). Applies to the `method = "range"` and
#' `method = "max"` methods.
#' @inheritDotParams ggplot2::sec_axis -trans
#'
#' @details The intent is to run this function before starting a plot. The
Expand Down Expand Up @@ -69,6 +72,7 @@ help_secondary <- function(
primary = c(0, 1),
secondary = c(0, 1),
method = c("range", "max", "fit", "ccf", "sortfit"),
na.rm = TRUE,
...
) {
primary <- enquo(primary)
Expand All @@ -82,8 +86,8 @@ help_secondary <- function(

help <- switch(
method,
"range" = help_sec_range(primary, secondary),
"max" = help_sec_max(primary, secondary),
"range" = help_sec_range(primary, secondary, na.rm = na.rm),
"max" = help_sec_max(primary, secondary, na.rm = na.rm),
"fit" = help_sec_fit(primary, secondary),
"ccf" = help_sec_ccf(primary, secondary),
"sortfit" = help_sec_sortfit(primary, secondary)
Expand Down Expand Up @@ -112,9 +116,9 @@ new_sec_axis <- function(trans = NULL, ...) {

# Methods -----------------------------------------------------------------

help_sec_range <- function(from, to) {
from <- range(from)
to <- range(to)
help_sec_range <- function(from, to, na.rm = TRUE) {
from <- range(from, na.rm = na.rm)
to <- range(to, na.rm = na.rm)

forward <- function(x) {
rescale(x, from = to, to = from)
Expand All @@ -125,9 +129,9 @@ help_sec_range <- function(from, to) {
list(forward = forward, reverse = reverse)
}

help_sec_max <- function(from, to) {
from <- range(from)
to <- range(to)
help_sec_max <- function(from, to, na.rm = TRUE) {
from <- range(from, na.rm = na.rm)
to <- range(to, na.rm = na.rm)

forward <- function(x) {
rescale_max(x, from = to, to = from)
Expand Down
6 changes: 6 additions & 0 deletions man/help_secondary.Rd

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

0 comments on commit 80c6491

Please sign in to comment.