Learn R Programming

NMOF (version 0.22-0)

qTable: Prepare LaTeX Table with Quartile Plots

Description

The function returns the skeleton of a table 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)

Arguments

X
a numeric matrix (or an object that can be coerced to a numeric matrix with as.matrix)
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 picture environment. See Details.
linethickness
the linethickness for LaTeX's picture environment. See Details.
cnames
the column names of X
circlesize
the size of the circle in LaTeX's picture environment
xoffset
defaults to 0. See Details.
yoffset
defaults to 0. See Details.
dec
the number of decimals
filename
if provided, output is cat into a file

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.

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 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. A number of parameters can be passed to LaTeX's picture environment: unitlength, xoffset, yoffset, linethickness. Sizes and lengths are functions of unitlength. 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. The vignette `qTableEx' shows some examples.

References

Gilli, M., Maringer, D. and Schumann, E. (2011) Numerical Methods and Optimization in Finance. Elsevier. http://www.elsevierdirect.com/product.jsp?isbn=9780123756626 Tufte, E. (2001) The Visual Display of Quantitative Information. 2nd edition, Graphics Press.

Examples

Run this code
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)

## 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)

Run the code above in your browser using DataLab