scientific_10x: Format numbers to scientific notation (10^#)

Description Usage Arguments Value Examples

View source: R/Helper_Functions.R

Description

Formats numbers to scientific notation using the form #.# x 10^# for display on axes. Leading zeros and '+' signs are removed from the output and spaces are inserted to match all exponents to uniform length for uniform display.

Usage

1
scientific_10x(values, digits = 1)

Arguments

values

A numeric vector

digits

A single integer value specifying the number of digits to display after the decimal, trailing zeroes will be preserved

Value

An expression

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
x <- 1:3
y <- c(0.1, 100, 1000)

# Base Plotting
originalMargins <- par()$mar
plot(y ~ x, 
     axes = F, 
     par(mar = c(5, 5, 4, 2) + 0.1), ylab = NA)
axis(1)
axis(2, 
     at = y, 
     labels = scientific_10x(y), 
     las = 2)
par(mar = originalMargins)

# ggplot2
ggplot2::qplot(x, y) + 
  ggplot2::scale_y_continuous(labels = scientific_10x)
ggplot2::qplot(x, y) + 
  ggplot2::scale_y_continuous(breaks = y, 
                              labels = scientific_10x(y, digits = 2))

jpshanno/ecoflux documentation built on May 19, 2019, 11:51 p.m.