qTable {NMOF} | R Documentation |
Prepare LaTeX Table with Quartile Plots
Description
The function returns the skeleton of a LaTeX tabular that contains the
median, minimum and maximum of the columns of a matrix X
. For
each column, a quartile plot is added.
Usage
qTable(X, xmin = NULL, xmax = NULL, labels = NULL, at = NULL,
unitlength = "5cm", linethickness = NULL,
cnames = colnames(X), circlesize = 0.01,
xoffset = 0, yoffset = 0, dec = 2, filename = NULL,
funs = list(median = median, min = min, max = max),
tabular.format, skip = TRUE)
Arguments
X |
a numeric matrix (or an object that can be coerced to a numeric
matrix with |
xmin |
optional: the minimum for the x-axis. See Details. |
xmax |
optional: the maximum for the x-axis. See Details. |
labels |
optional: labels for the x-axis. |
at |
optional: where to put labels. |
unitlength |
the unitlength for LaTeX's |
linethickness |
the linethickness for LaTeX's |
cnames |
the column names of |
circlesize |
the size of the circle in LaTeX's |
xoffset |
defaults to 0. See Details. |
yoffset |
defaults to 0. See Details. |
dec |
the number of decimals |
filename |
if provided, output is |
funs |
A
|
tabular.format |
optional: character string like |
skip |
Adds a newline at the end of the tabular. Default is
|
Details
The function creates a one-column character matrix that can be put into
a LaTeX file (the matrix holds a tabular). It relies on LaTeX's
picture
environment and should work for LaTeX and pdfLaTeX. Note
that the tabular needs generally be refined, depending on the settings
and the data.
The tabular has one row for every column of X
(and header and
footer rows). A given row contains (per default) the median, the minimum
and the maximum of the column; it also includes a picture
environment the shows a quartile plot of the distribution of the
elements in that column. Other functions can be specified via argument
funs
.
A number of parameters can be passed to LaTeX's picture
environment: unitlength
, xoffset
, yoffset
,
linethickness
. Sizes and lengths are functions of
unitlength
(linethickness
is an exception; and while
circlesize
is a multiple of unitlength, it will not translate
into an actual diameter of more than 14mm).
The whole tabular environment is put into curly brackets so that the settings do not change settings elsewhere in the LaTeX document.
If xmin
, xmax
, labels
and at
are not
specified, they are computed through a call to pretty
from
the base package. If limits are specified, then both xmin
and xmax
must be set; if labels are used, then both labels
and at
must be specified.
To use the function in a vignette, use cat(tTable(X))
(and
results=tex
in the code chunk options). The vignette
qTableEx
shows some examples.
Value
A matrix of mode character. If filename
is specified then
qTable
will have the side effect of writing a textfile with a
LaTeX tabular.
Note
qTable
returns a raw draft of a table for LaTeX. Please, spend
some time on making it pretty.
Author(s)
Enrico Schumann
References
Gilli, M., Maringer, D. and Schumann, E. (2019) Numerical Methods and Optimization in Finance. 2nd edition. Elsevier. doi:10.1016/C2017-0-01621-X
Tufte, E. (2001) The Visual Display of Quantitative Information. 2nd edition, Graphics Press.
Schumann, E. (2023) Financial Optimisation with R (NMOF Manual). http://enricoschumann.net/NMOF.htm#NMOFmanual
Examples
x <- rnorm(100, mean = 0, sd = 2)
y <- rnorm(100, mean = 1, sd = 2)
z <- rnorm(100, mean = 1, sd = 0.5)
X <- cbind(x, y, z)
res <- qTable(X)
print(res)
cat(res)
## Not run:
## show vignette with examples
qt <- vignette("qTableEx", package = "NMOF")
print(qt)
edit(qt)
## create a simple LaTeX file 'test.tex':
## ---
## \documentclass{article}
## \begin{document}
## \input{res.tex}
## \end{document}
## ---
res <- qTable(X, filename = "res.tex", yoffset = -0.025, unitlength = "5cm",
circlesize = 0.0125, xmin = -10, xmax = 10, dec = 2)
## End(Not run)