Debian Codegraph @

man/eaxis.Rd

raw
1 \name{eaxis}
2 \alias{eaxis}
3 \title{Extended / Engineering Axis for Graphics}
4 \description{%% ---> ../R/prettylab.R
5 An extended \code{\link[graphics]{axis}()} function which labels more
6 prettily, in particular for log-scale axes.
7
8 It makes use of \link{plotmath} or (LaTeX) \code{\link{expression}}s of
9 the form \eqn{k \times 10^k}{k * 10^k} for labeling a
10 log-scaled axis and when otherwise exponential formatting would be
11 used (see \code{\link{pretty10exp}}).
12 }
13 \usage{
14 eaxis(side, at = if(log) axTicks(side, axp=axp, log=log, nintLog=nintLog)
15 else axTicks(side, axp=axp, log=log),
16 labels = NULL, log = NULL,
17 use.expr = log || format.info(as.numeric(at), digits=7)[3] > 0,
18 f.smalltcl = 3/5, at.small = NULL, small.mult = NULL, equidist.at.tol = 0.002,
19 small.args = list(),
20 draw.between.ticks = TRUE, between.max = 4,
21 outer.at = TRUE, drop.1 = TRUE, sub10 = FALSE, las = 1,
22 nintLog = max(12, par("lab")[2 - is.x]),
23 axp = NULL, n.axp = NULL, max.at = Inf,
24 lab.type = "plotmath", lab.sep = "cdot",
25 \dots)
26 }
27 \arguments{
28 \item{side}{integer in 1:4, specifying side of \code{\link{axis}}.}
29 \item{at}{numeric vector of (\dQuote{normalsized}) tick locations; by
30 default \code{\link[graphics]{axTicks}(side, ..)}, i.e., the same as
31 \code{\link{axis}()} would use.}
32 \item{labels}{\code{NULL} (default), \code{\link{logical}},
33 \code{character} or \code{expression}, as in \code{\link{axis}()};
34 in addition, if \code{NA}, \code{labels = TRUE} is passed to
35 \code{\link{axis}()}, i.e. \code{\link{pretty10exp}} is \emph{not}
36 used. Use \code{FALSE} to suppress any labeling.}
37 \item{log}{logical or \code{NULL} specifying if log-scale should be
38 used; the default depends on the current plot's axis.}
39 \item{use.expr}{logical specifying if \code{\link{pretty10exp}(.)} should
40 be used for constructing \code{labels} when they are \code{NULL}. The
41 default is typically good enough, but you may occasionally \emph{force}
42 \code{use.expr = TRUE}.}
43 \item{f.smalltcl}{factor specifying the lengths of the small ticks in
44 proportion to the normalsized, labeled ticks.}
45 \item{at.small}{locations of \emph{small} ticks; the default,
46 \code{NULL}, uses \code{small.mult} and constructs \dQuote{smart}
47 locations.}
48 \item{small.mult}{positive integer (or \code{NULL}), used when
49 \code{at.small} is NULL to indicate which multiples of
50 \code{at} (typically \code{\link{axTicks}()}) should be used as
51 \dQuote{small ticks}. The default \code{NULL} will use \code{9} in
52 the log case and a number in 2:5 otherwise.}% depending on scale details
53 \item{equidist.at.tol}{a small positive number, a tolerance to be used
54 for checking equidistant \code{at} values. Used to be hardwired at
55 \code{.001} which was seen to be too small; increase it when necessary.}
56 \item{small.args}{optional \code{\link{list}} of further arguments to
57 the (second) \code{\link{axis}()} call which draws the \emph{small} ticks.}
58 \item{draw.between.ticks}{(only if \code{log} is true): logical indicating
59 that possible (non-small) ticks between the labeled (via \code{at})
60 ones should be drawn as well (and possibly also used for \code{at.small}
61 construction), see also \code{between.max}.}
62 \item{between.max}{(only if \code{log} and \code{draw.between.ticks}
63 are true): integer indicating ticks should be drawn (approximately)
64 between the labeled ones.}
65 \item{outer.at}{logical specifying that \code{at.small} should also be
66 constructed outside the \code{at} range, but still inside the
67 corresponding \code{\link{par}("usr")}.}
68 \item{drop.1}{logical specifying if \eqn{1 \times}{1 *} should be dropped
69 from labels, passed to \code{\link{pretty10exp}()}.}
70 \item{sub10}{logical, integer (of length 1 or 2), \code{"10"} or \code{"100"},
71 indicating if
72 some \eqn{10^k} should be simplified to \dQuote{traditional}
73 formats, see \code{\link{pretty10exp}}.}
74 \item{nintLog}{only used in \R > 2.13.x, when \code{log} is true:
75 approximate (lower bound on) number of intervals for log scaling.}
76 \item{axp}{to be passed to \code{\link{axTicks}()} if \code{at} is not
77 specified.}
78 \item{n.axp}{to be set to \code{axp[3]} when \code{axp} and \code{at}
79 are not specified, in order to tweak the \emph{number} of (non-small)
80 tick marks produced from \code{\link{axTicks}(..)}, notably when
81 \code{log} is true, set \code{n.axp} to 1, 2, or 3:
82 \describe{
83 \item{1:}{will produce tick marks at \eqn{10^j} for integer \eqn{j},}
84 \item{2:}{gives marks \eqn{k 10^j} with \eqn{k \in \{1, 5\}}{k in {1,5}},}
85 \item{3:}{gives marks \eqn{k 10^j} with \eqn{k \in \{1, 2, 5\}}{k in {1,2,5}}}
86 } see \code{'xaxp'} on the \code{\link{par}} help page.}
87 \item{max.at}{maximal number of \code{at} values to be used
88 effectively. If you don't specify \code{at} yourself carefully, it
89 is recommended to set this to something like \code{25}, but this is
90 not the default, for back compatibility reasons.}
91 \item{las, \dots}{arguments passed to (the first) \code{\link{axis}}
92 call. Note that the default \code{las = 1} differs from
93 \code{axis}'s default \code{las = 0}.}
94 \item{lab.type}{string, passed to \code{\link{pretty10exp}} to choose
95 between default \code{\link{plotmath}} or LaTeX label format.}
96 \item{lab.sep}{separator between mantissa and exponent for LaTeX labels,
97 see \code{\link{pretty10exp}}.}
98 }
99 \author{Martin Maechler}
100 \seealso{\code{\link[graphics]{axis}},
101 \code{\link[graphics]{axTicks}},
102 \code{\link{axTexpr}},
103 \code{\link{pretty10exp}}.
104 }
105 \examples{
106 x <- lseq(1e-10, 0.1, length = 201)
107 plot(x, pt(x, df=3), type = "l", xaxt = "n", log = "x")
108 eaxis(1)
109 ## without small ticks:
110 eaxis(3, at.small=FALSE, col="blue")
111
112 ## If you like the ticks, but prefer traditional (non-"plotmath") labels:
113 plot(x, gamma(x), type = "l", log = "x")
114 eaxis(1, labels=NA)
115
116 x <- lseq(.001, 0.1, length = 1000)
117 plot(x, sin(1/x)*x, type = "l", xaxt = "n", log = "x")
118 eaxis(1)
119 eaxis(3, n.axp = 1)# -> xaxp[3] = 1: only 10^j (main) ticks
120
121 ## non- log-scale : draw small ticks, but no "10^k" if not needed:
122 x <- seq(-100, 100, length = 1000)
123 plot(x, sin(x)/x, type = "l", xaxt = "n")
124 eaxis(1) # default -> {1, 2, 5} * 10^j ticks
125 eaxis(3, n.axp = 2)# -> xaxp[3] := 2 -- approximately two (main) ticks
126
127 x <- seq(-1, 1, length = 1000)
128 plot(x, sin(x)/x, type = "l", xaxt = "n")
129 eaxis(1, small.args = list(col="blue"))
130
131 x <- x/1000
132 plot(x, 1-sin(x)/x, type = "l", xaxt = "n", yaxt = "n")
133 eaxis(1)
134 eaxis(2)
135 ## more labels than default:
136 op <- par(lab=c(10,5,7))
137 plot(x, sin(x)/x, type = "l", xaxt = "n")
138 eaxis(1) # maybe (depending on your canvas), there are too many,
139 ## in that case, maybe use
140 plot(x, sin(x)/x, type = "l", xaxt = "n")
141 eaxis(1, axTicks(1)[c(TRUE,FALSE)]) # drop every 2nd label
142 eaxis(3, labels=FALSE)
143
144 ## ore use 'max.at' which thins as well:
145 plot(x, sin(x)/x, type = "l", xaxt = "n")
146 eaxis(1, max.at=6)
147 par(op)
148
149 ### Answering R-help "How do I show real values on a log10 histogram", 26 Mar 2013
150 ## the data:
151 set.seed(1); summary(x <- rlnorm(100, m = 2, sdl = 3))
152 ## the plot (w/o x-axis) :
153 r <- hist(log10(x), xaxt = "n", xlab = "x [log scale]")
154 ## the nice axis:
155 axt <- axTicks(1)
156 eaxis(1, at = axt, labels = pretty10exp(10^axt, drop.1=TRUE))
157 ## Additionally demo'ing 'sub10' options:
158 plot(r, xaxt="n")
159 eaxis(1, at = axt, labels = pretty10exp(10^axt, drop.1=TRUE, sub10 = 2))
160 ## or
161 plot(r, xaxt="n")
162 eaxis(1, at = axt, labels = pretty10exp(10^axt, drop.1=TRUE, sub10 = "10"))
163 ## or
164 plot(r, xaxt="n")
165 eaxis(1, at = axt, labels = pretty10exp(10^axt, drop.1=TRUE, sub10 = c(-2, 2)))
166 }
167 \keyword{aplot}
168
169 % LocalWords: axp nintLog