Learn R Programming

berryFunctions (version 1.7.1)

logAxis: label logarithmic axes

Description

shortcut to calling logVals, axis and abline

Usage

logAxis(side=1, log=NULL, lcol="grey", lty=1, lwd=1, expr, las=1,
from, to, Range, base, big.mark="'", decimal.mark=".", scientific=FALSE,
exponent=5, expobase1=FALSE, allbase=1:9, ...)

Arguments

side
Which axis are to be labeled? Can be a vector within 1:4. DEFAULT: 1
log
Is the axis logarithmic by plot(log="x")? internal DEFAULT: par("xlog") or "ylog". DEFAULT: NULL
lcol
Color of gridlines drawn in the graph with abline, NA to suppress. DEFAULT: "grey"
lty, lwd
Type of gridlines. DEFAULT: 1
expr
Expression drawing over the ablines, like (points(x,y). Can be code within {braces}.
las
LabelAxisStyle for the orientation of the labels. DEFAULT: 1
from
Lower exponent OR vector with data, as in logVals. DEFAULT based on par("usr")
to
High end exponent. DEFAULT: internally based on par("usr")
Range
Override from and to as range.
base
Bases to be used in logVals. DEFAULT: c(1,2,5) or 1, depending on from and to.
big.mark
Symbol separating thousands, eg. space, comma, dot, etc. see "format" and "prettyNum". DEFAULT: "'"
decimal.mark
Character separating comma values, see "format" and "prettyNum". DEFAULT: "."
scientific
See format. DEFAULT: FALSE
exponent
Starting at which exponent should logVals return an expression with exponents? DEFAULT: 5
expobase1
Should "n * " be appended before 10^exp if n=1? DEFAULT: FALSE
allbase
base for $all (for horizontal lines). DEFAULT: 1:9
...
further arguments passed to axis, like lwd, col.ticks, hadj, lty, ...

Value

  • An invisible list with
  • valsValues for lines and label positions
  • labsFormatted values for labels
  • allValues for lines

See Also

logVals, log10

Examples

Run this code
x <- 10^runif(200, -1, 2)
plot(x, yaxt="n", log="y", pch=16)
logAxis(2)
# overplot vertical lines:
logAxis(2, expr=points(x, pch=16), base=1, col.axis=4, font=2)

# plots where log="x" is not possible:
hist(log10(x), breaks=20, col.axis="grey", main="")
logAxis(side=3, expr=hist(log10(x), breaks=20, add=TRUE, col=3))

# automatic calculation of from, to and base:
plot(1:3, axes=FALSE)
logAxis(1:2) # side can be a vector - nice, huh?
plot(-1:4, axes=FALSE)
logAxis(1:2) # treshold for base 1 instead of c(1,2,5) at 4 exponents exceeded.

par(mar=c(3,3,1,4))
plot(8:15) ;  logAxis(4) # with exponents if they are above 5
plot(10^(1:4), ylim=10^c(4,1), type="o", log="y") # reverse axis:
plot(10^(1:5), log="y"); logAxis(4, exponent=3) # different treshold
plot(10^(1:5), log="y"); logAxis(4, expon=3, base=c(1,2,5), expobase1=TRUE)
plot(-8:5); logAxis(4, allbase=c(1,2,5)) # In case you want to mislead...

Run the code above in your browser using DataLab