R/xgx_labels_log10.R

Defines functions xgx_labels_log10

Documented in xgx_labels_log10

#' Nice labels for log10.
#'
#' Returns a set of labels for ggplot
#'
#' @param breaks, breaks for the function
#'
#' @return either character or expression
#'
#' @examples
#' print(xgx_labels_log10(c(1e-5, 1, 1e5)))
#' 
#' @export
xgx_labels_log10 <- function(breaks) {
  labels <- as.character(breaks)
  if (all(log10(breaks) == as.integer(log10(breaks)), na.rm = TRUE)
      && (min(breaks, na.rm = TRUE) < 0.001 ||
          max(breaks, na.rm = TRUE) > 9999)) {
    labels <- as.character(breaks)
  }

  return(labels)
}

Try the xgxr package in your browser

Any scripts or data that you put into this service are public.

xgxr documentation built on March 31, 2023, 11:46 p.m.