Learn R Programming

berryFunctions (version 1.4)

logVals: Create log-axis values and labels

Description

create nice values and labels to write at logartihmic axes

Usage

logVals(from=-3, to=4, Range=range(from, to), base=1,
big.mark="'", decimal.mark=".", scientific=FALSE)

Arguments

from
lower exponent OR vector with data
to
high end
Range
or give from and to as range
base
bases to be used, eg. c(1,2,5)
big.mark
symbol separating thousands, eg. space, comma, dot, etc. see format and prettyNum
decimal.mark
character separating comma values, see format and prettyNum
scientific
see format

Value

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

See Also

log10

Examples

Run this code
# Easiest use: vector with data (logVals automatically finds range):
y <- 10^runif(50, -1, 2)
plot(y, log="y") # not much control over placement and format of labels
plot(y, log="y", yaxt="n")
# now do this better, with custom bases:
lv <- logVals(y, base=c(1,2,5) )
axis(2, lv$vals, lv$labs, las=1)

# Default arguments:
lv <- logVals()
str(lv) # values, formatted labels, all 10^x values for lines
plot(1, ylim=c(1e-3, 1e4), log="y", yaxt="n", yaxs="i")
abline(h=lv$all, col=8 )
box("plot")
axis(2, lv$vals, lv$labs, las=1)
lines(seq(0.5, 1.5, len=50), 10^runif(50, -3, 4), col=2)

# Formatting labels:
logVals(                )$labs
logVals(scient=TRUE     )$labs
logVals(big.mark=""    )$labs
logVals(big=".", dec=",")$labs # German style (not recommended)

Run the code above in your browser using DataLab