axTexpr               package:sfsmisc               R Documentation

_A_x_i_s _T_i_c_k_s _E_x_p_r_e_s_s_i_o_n_s _i_n _N_i_c_e _1_0 ** _k _F_o_r_m

_D_e_s_c_r_i_p_t_i_o_n:

     Produce nice a * 10^k expressions for 'axis' labeling instead of
     the scientific notation '"a E<k>"'.

_U_s_a_g_e:

     axTexpr(side, at = axTicks(side, axp = axp, usr = usr, log = log),
             axp = NULL, usr = NULL, log = NULL,
             drop.1 = FALSE)

_A_r_g_u_m_e_n_t_s:

    side: integer in 1:4 specifying the axis side, as for 'axis'.

      at: numeric vector; with identical default as in 'axTicks()'.

axp, usr, log: as for 'axTicks()'.

  drop.1: logical indicating if 1 * should be dropped from the
          resulting expressions.

_D_e_t_a_i_l_s:

     This is just a utility with the same arguments as 'axTicks',
     calling 'pretty10exp(at, *)'.

_V_a_l_u_e:

     an expression of the same length as 'x', with elements of the form
     'a %*% 10 ^ k'.

_A_u_t_h_o_r(_s):

     Martin Maechler

_S_e_e _A_l_s_o:

     'pretty10exp'; 'axis', 'axTicks'.

_E_x_a_m_p_l_e_s:

     x <- 1e7*(-10:50)
     y <- dnorm(x, m=10e7, s=20e7)
     plot(x,y)## not really nice,  the following is better:

     ## For horizontal y-axis labels, need more space:
     op <- par(mar= .1+ c(5,5,4,1))
     plot(x,y, axes= FALSE, frame=TRUE)
     aX <- axTicks(1); axis(1, at=aX, label= axTexpr(1, aX))
     ## horizontal labels on y-axis:
     aY <- axTicks(2); axis(2, at=aY, label= axTexpr(2, aY), las=2)
     par(op)

     ### -- only 'x' and using log-scale there:
     plot(x,y, xaxt= "n", log = "x")
     aX <- axTicks(1); axis(1, at=aX, label= axTexpr(1, aX))

     ## Now an `` engineer's version '' ( more ticks; only label "10 ^ k" ) :

     axp <- par("xaxp") #-> powers of 10 *inside* 'usr'
     axp[3] <- 1 # such that only 10^. are labeled
     aX <- axTicks(1, axp = axp)
     xu <- 10 ^ par("usr")[1:2]
     e10 <- c(-1,1) + round(log10(axp[1:2])) ## exponents of 10 *outside* 'usr'
     v <- c(outer(1:9, e10[1]:e10[2], function(x,E) x * 10 ^ E))
     v <- v[xu[1] <= v & v <= xu[2]]

     plot(x,y, xaxt= "n", log = "x", main = "engineer's version of x - axis")
     axis(1, at = aX, label = axTexpr(1, aX, drop.1=TRUE)) # `default'
     axis(1, at = v,  label = FALSE, tcl = 2/3 * par("tcl"))

