to_scientific: Convert numbers into formatted scientific notation...

View source: R/to_scientific.R

to_scientificR Documentation

Convert numbers into formatted scientific notation expressions

Description

This function converts a vector of numbers to formatted scientific notation expressions. It is called by label_sci() to convert the ggplot2 scale function labels to scientific format.

Usage

to_scientific(
  x,
  digits = 2,
  max_cut = 10^5,
  min_cut = 10^-3,
  common = FALSE,
  factor = NULL,
  trailing = TRUE,
  units = NULL
)

Arguments

x

Numeric vector, gives numbers to convert to scientific notation

digits

Number of significant figures to display in the converted output

max_cut

Above this number, values will be converted into scientific format (inclusive)

min_cut

Below this number, values will be converted into scientific format (exclusive)

common

Should the formatted numbers share a common exponential factor?

factor

Provides a value for the common exponential factor; if NULL, the most occurring exponent will be used

trailing

Should trailing zeros be included in the formatted number?

units

If provided, adds units to the converted output

Value

An expression containing the input numbers in scientific format

Examples

a <- c(NA, 10657, 0.00187, 0.0005, 102, 0)
to_scientific(a)

christyray/sciscales documentation built on April 14, 2022, 2:05 p.m.