R/scale_y_percentage.R

#' scale_y_percentage
#'
#' @export
scale_y_percentage <- function (
  ...,
  digits = 0,
  expand = c(0, 0),
  reverse = FALSE
) {

  if (isTRUE(reverse)) {
    label_fun <- function (x) {
      format_percentage(1 - x, digits = digits)
    }
  } else {
    label_fun <- function (x) {
      format_percentage(x, digits = digits)
    }
  }

  scale_y_continuous(
    ...,
    labels = label_fun,
    expand = expand)

}
BAAQMD/ggtools documentation built on Feb. 8, 2023, 6:22 p.m.