Learn R Programming

berryFunctions (version 1.22.5)

logAxis: Label logarithmic axes

Description

Shortcut to calling logVals, axis and abline

Usage

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

Value

An invisible list with

vals

Values for lines and label positions

labs

Formatted values for labels

all

Values for lines

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

labels

Labels passed to axis. "FALSE" to suppress labeling. DEFAULT: NULL (internally, logVals$labs

allticks

Place all intermediate ticklines at the axis (without labeling). DEFAULT: FALSE

allargs

List of arguments passed to axis for allticks=TRUE. DEFAULT: NULL

expr

Expression drawing over the ablines, like (points(x,y). Can be code within curly 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: NA -> 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

box

Draw box at the end to overplot ablines crossing the box? DEFAULT: TRUE

...

Further arguments passed to axis, like lwd, col.ticks, hadj, lty, ...

Author

Berry Boessenkool, berry-b@gmx.de, Sept 2014

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))
# or just use the new logHist function (Feb 2016):
logHist(x, breaks=20, 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.

plot(1:3, axes=FALSE)
logAxis(1:2, allticks=TRUE, lcol=NA)

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