endSCALE: Plot nice scale at end of trace.

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/endSCALE.R

Description

Calculate nice scale to use at the end of a plot. Use as an alternative to magicaxis.

Usage

1
endSCALE(arange, digits = 3)

Arguments

arange

2-vector of bounds

digits

number of digits to use

Details

The function returns information for plotting a nice bounds axis similar to MATLAB plotting style.

Value

character vector: min, max, exponent

Note

If the bounds span multiple orders of magnitude, may want to make adjustments (like setting a negative exponent bound to zero)

Author(s)

Jonathan M. Lees<[email protected]>

See Also

plotwlet

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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
M = 1e-19
m = M

for(i in 1:10) {
  z = c( rnorm(1)*m ,  rnorm(1)*M )
  print(z)
  print( endSCALE(z)   )

##########  use in plotting:

x = seq(from=0, by=0.01, length=200)
a = 10000*rnorm(length(x))
old.par <- par(no.readonly = TRUE)
############  make room on the right margin
MAI = par("mai")
 MAI[4] = MAI[2]
par(mfrow=c(2,1))
 par(mai=MAI)
par(xaxs='i', yaxs='i')

plot(x,a, type='l')
  axtrace = range(a)
    Elabs =  endSCALE(axtrace)
    exp = parse(text = Elabs[3])
 axis(4, at=axtrace , labels=Elabs[1:2] , pos=max(x), tick=TRUE , line=0.5, cex.axis=0.8,las=2)
       mtext(exp, side = 3, at = max(x), line=0.5, adj=-1  , cex=0.8)
    mtext("m/s", side = 4, at =mean(axtrace) , line=0.5   , cex=0.8 ,las=1 )

a = rnorm(length(x))/100000


plot(x,a, type='l')
  axtrace = range(a)
    Elabs =  endSCALE(axtrace)
    exp = parse(text = Elabs[3])
 axis(4, at=axtrace , labels=Elabs[1:2] , pos=max(x), tick=TRUE , line=0.5, cex.axis=0.8,las=2)
       mtext(exp, side = 3, at = max(x), line=0.5, adj=-1  , cex=0.8)
    mtext("m/s", side = 4, at =mean(axtrace) , line=0.5   , cex=0.8 ,las=1 )

par(old.par)


} 

RPMG documentation built on Jan. 20, 2018, 9:04 a.m.