Aliases: axTicks
Keywords: dplot
### ** Examples plot(1:7, 10*21:27)
axTicks(1)
[1] 1 2 3 4 5 6 7
axTicks(2)
[1] 210 220 230 240 250 260 270
stopifnot(identical(axTicks(1), axTicks(3)), identical(axTicks(2), axTicks(4))) ## Show how axTicks() and axis() correspond : op <- par(mfrow = c(3, 1)) for(x in 9999 * c(1, 2, 8)) { plot(x, 9, log = "x") cat(formatC(par("xaxp"), width = 5),";", T <- axTicks(1),"\n") rug(T, col = adjustcolor("red", 0.5), lwd = 4) }
1000 1e+05 3 ; 200 500 1000 2000 5000 10000 20000 50000 1e+05 2e+05 5e+05
1000 1e+06 2 ; 500 1000 5000 10000 50000 1e+05 5e+05 1e+06
1000 1e+07 1 ; 1000 10000 1e+05 1e+06 1e+07
par(op) x <- 9.9*10^(-3:10) plot(x, 1:14, log = "x")
axTicks(1) # now length 7, in R <= 2.13.x gave 'nintLog = Inf' res; then
[1] 1e-02 1e+00 1e+02 1e+04 1e+06 1e+08 1e+10
## 1e-01 1e+01 1e+03 1e+05 1e+07 1e+09 1e+11 ; since R 4.2.0: 1e-2 1e0 1e2 .. 1e10 axTicks(1, nintLog = Inf) # rather too many
[1] 1e-02 1e-01 1e+00 1e+01 1e+02 1e+03 1e+04 1e+05 1e+06 1e+07 1e+08 1e+09 [13] 1e+10 1e+11
## An example using axTicks() without reference to an existing plot ## (copying R's internal procedures for setting axis ranges etc.), ## You do need to supply _all_ of axp, usr, log, nintLog ## standard logarithmic y axis labels ylims <- c(0.2, 88) get_axp <- function(x) 10^c(ceiling(x[1]), floor(x[2])) ## mimic par("yaxs") == "i" usr.i <- log10(ylims) (aT.i <- axTicks(side = 2, usr = usr.i, axp = c(get_axp(usr.i), n = 3), log = TRUE, nintLog = 5))
[1] 0.2 0.5 1.0 2.0 5.0 10.0 20.0 50.0
## mimic (default) par("yaxs") == "r" usr.r <- extendrange(r = log10(ylims), f = 0.04) (aT.r <- axTicks(side = 2, usr = usr.r, axp = c(get_axp(usr.r), 3), log = TRUE, nintLog = 5))
[1] 0.2 0.5 1.0 2.0 5.0 10.0 20.0 50.0 100.0
## Prove that we got it right : plot(0:1, ylims, log = "y", yaxs = "i")
stopifnot(all.equal(aT.i, axTicks(side = 2))) plot(0:1, ylims, log = "y", yaxs = "r")
stopifnot(all.equal(aT.r, axTicks(side = 2)))