logVals: Create log-axis values and labels

View source: R/logVals.R

logValsR Documentation

Create log-axis values and labels

Description

Create nice values and labels to write at logarithmic axes

Usage

logVals(
  from = -7,
  to = 7,
  Range,
  base = 1,
  big.mark = "'",
  decimal.mark = ".",
  scientific = FALSE,
  exponent = Inf,
  expobase1 = FALSE,
  allbase = 1:9,
  ...
)

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). Use base=NA to switch between 1 and c(1,2,5) depending on range. DEFAULT 1

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

exponent

Starting at which exponent should labs be an expression with exponents? Compare to options("scipen"). This is mainly for logAxis and only for base 1. DEFAULT: Inf

expobase1

Should "n * " be appended before 10^exp if n=1? DEFAULT: FALSE

allbase

Base for $all (for horizontal lines). DEFAULT: 1:9

...

Ignored arguments

Value

A list with

vals

Values for lines and label positions

labs

Formatted values for labels

all

Values for lines

Author(s)

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

See Also

log10, logAxis, https://web.archive.org/web/20190504213250/https://r.789695.n4.nabble.com/expression-exponent-labeling-td4661174.html

Examples


# 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(exponent=5      )$labs # expression with exponent, see logAxis
logVals(big.mark=" "    )$labs
logVals(big=".", dec=",")$labs # German style (not recommended)


berryFunctions documentation built on May 29, 2024, 4:01 a.m.