axisTicks {grDevices} | R Documentation |
Compute Pretty Axis Tick Scales
Description
Compute pretty axis scales and tick mark locations, the same way as traditional R graphics do it. This is interesting particularly for log scale axes.
Usage
axisTicks(usr, log, axp = NULL, nint = 5)
.axisPars(usr, log = FALSE, nintLog = 5)
Arguments
usr |
numeric vector of length 2, with |
log |
logical indicating if a log scale is (thought to be) in use. |
axp |
numeric vector of length 3, |
nint , nintLog |
positive integer value indicating
(approximately) the desired number of intervals.
|
Details
axisTicks(usr, *)
calls .axisPars(usr, ..)
to set
axp
when that is missing or NULL
.
Apart from that, axisTicks()
just calls the C function
CreateAtVector()
in ‘R/src/main/plot.c’ which is also
called by the base graphics package function
axis(side, *)
when its argument at
is not
specified.
Since R 4.1.0, the underlying C CreateAtVector()
has been tuned
to provide a considerably more balanced (symmetric) set of tick locations.
Value
axisTicks()
returns a numeric vector of potential axis tick
locations in case of log=TRUE
in the original scale, of length
approximately nint+1
.
.axisPars()
returns a list
with components
axp |
numeric vector of length 2, |
n |
integer (code), with the same meaning as
|
See Also
axTicks
,
axis
, and par
all from
the graphics package.
Examples
##--- Demonstrating correspondence between graphics'
##--- axis() and the graphics-engine agnostic axisTicks() :
require("graphics")
plot(10*(0:10)); (pu <- par("usr"))
aX <- function(side, at, ...)
axis(side, at = at, labels = FALSE, lwd.ticks = 2, col.ticks = 2,
tck = 0.05, ...)
aX(1, print(xa <- axisTicks(pu[1:2], log = FALSE))) # x axis
aX(2, print(ya <- axisTicks(pu[3:4], log = FALSE))) # y axis
axisTicks(pu[3:4], log = FALSE, nint = 10)
## -------------------- Log Scale --------------------------------
x <- c(10, 1000)
# _____
axisTicks(log10(x), log = TRUE) # 10 20 50 .... 1000
plot(10*(0:10), log = "y"); (pu <- par("usr")) # ... ... 0.96 2.04
aX(2, print(ya <- axisTicks(pu[3:4], log = TRUE))) # 10 20 50 100 (y axis)
plot(2^(0:9), log = "y"); (pu <- par("usr")) #
aX(2, print(ya <- axisTicks(pu[3:4], log = TRUE))) # y axis
## 'usr' corresponds to log10(<range>) :
stopifnot(ya == axisTicks(log10(c(1, 512)), log=TRUE))