R/utils_color_breaks.R

Defines functions utils_color_breaks

Documented in utils_color_breaks

#' Auto Breaks for Matrix Plotting Functions
#'
#' @param m (required, numeric matrix) distance or cost matrix generated by [psi_distance_matrix()] or [psi_cost_matrix()], but any numeric matrix will work. Default: NULL
#' @param n (required, integer) number of colors to compute the breaks for. Default: 100
#'
#' @return numeric vector
#' @autoglobal
#' @export
#' @family internal_plotting
utils_color_breaks <- function(
    m = NULL,
    n = 100
    ){

  m <- utils_check_args_matrix(m = m)

  m.range <- range(m, na.rm = TRUE)

  a <- seq(
    from = m.range[1],
    to = m.range[2],
    length.out = n
  )

  b <- (a[2]- a[1])/2

  breaks <- c(a[1] - b, a + b)

  breaks

}

Try the distantia package in your browser

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

distantia documentation built on April 4, 2025, 5:42 a.m.