sistring: f2si converts floating-point number to a string with SI...

Description Usage Arguments Details Value Warning Author(s) References Examples

Description

Convert a single or a list of float or integer to a string using SI prefixes.

Usage

1
f2si(number, unit="")

Arguments

number

number to convert

unit

string to attach behind the SI prefix

Details

Main application of this function is to get nice strings to place at axis ticks. In this case some prefixes like deka are not used. This function will only generate 10^(3*n) prefixes for positive numbers at the moment. This may change soon.

Value

comp1

string using SI prefixes

Warning

package is still in alpha stage

Author(s)

Jonas Stein news@jonasstein.de https://github.com/jonasstein/sitools

References

http://www.bipm.org/en/si/si_brochure/chapter3/prefixes.html

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library(sitools)

# convert single number
f2si(10000)

# convert single number with unit
f2si(0.023, unit="V")

# convert list of numbers
numbers <- c(1e5, 3.5e19, 0.004)
f2si(numbers)


# how to create fancy axis labels
# generate some data
xdata <- 10^(0:10)
ydata <- sin(xdata)^2

# lets assume the ticks should be at 1,2,4 ..10,20,40...
tickvalues <- 10^(0:10) 

# plot the data and generate axis
plot(x=xdata, y=ydata, log="x", xlim=c(1,1e10),  xaxt="n",xlab="Frequency (Hz)")
axis(1, at=tickvalues, labels=f2si(tickvalues))

Example output

[1] "10 k"
[1] "23 mV"
[1] "100 k" "35 E"  "4 m"  

sitools documentation built on May 2, 2019, 3:46 p.m.