From: arnima Date: Tue, 30 Sep 2014 14:08:04 +0000 (+0000) Subject: Vignette: remove aov/lm/glm examples, combine row/colname, add tabcolsep X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=c432fe1a3a44e6da51602578477863aa0c1e206d;p=xtable.git Vignette: remove aov/lm/glm examples, combine row/colname, add tabcolsep git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@61 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- diff --git a/pkg/vignettes/xtableGallery.Rnw b/pkg/vignettes/xtableGallery.Rnw index 9fccd7b..4451b0e 100644 --- a/pkg/vignettes/xtableGallery.Rnw +++ b/pkg/vignettes/xtableGallery.Rnw @@ -44,7 +44,7 @@ xtable(tli[1:10, ]) \subsection{Matrix} <>= design.matrix <- model.matrix(~ sex*grade, data = tli[1:10, ]) -xtable(design.matrix) +xtable(design.matrix, digits = 0) @ \subsection{aov} @@ -83,75 +83,6 @@ xtable(fm3) xtable(anova(fm3)) @ -\subsection{More aov} -<>= -## Venables and Ripley (1997, p. 210) -N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0) -P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0) -K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0) -yield <- c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,62.8,55.8,69.5,55.0, - 62.0,48.8,45.5,44.2,52.0,51.5,49.8,48.8,57.2,59.0,53.2,56.0) -npk <- data.frame(block = gl(6,4), N = factor(N), P = factor(P), - K = factor(K), yield = yield) -npk.aov <- aov(yield ~ block + N*P*K, npk) -xtable(npk.aov) -@ - -\p\textbf{\itshape Anova table} -<>= -xtable(anova(npk.aov)) -@ - -\p\textbf{\itshape Summary table} -<>= -xtable(summary(npk.aov)) -@ - -\newpage - -\p -<>= -## Alternative multistratum model -op <- options(contrasts = c("contr.helmert", "contr.treatment")) -npk.aovE <- aov(yield ~ N*P*K + Error(block), npk) -options(op) -xtable(npk.aovE) -@ - -\p -<>= -xtable(summary(npk.aovE)) -@ - -\subsection{More lm} -<>= -## Dobson (1990, p. 9) plant weight data -ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) -trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) -group <- gl(2,10,20, labels = c("Ctl","Trt")) -weight <- c(ctl, trt) -lm.D9 <- lm(weight ~ group) -xtable(lm.D9) -@ - -\p -<>= -xtable(anova(lm.D9)) -@ - -\newpage - -\subsection{More glm} -<>= -## Dobson (1990, p. 93) randomized controlled trial -counts <- c(18,17,15,20,10,20,25,13,12) -outcome <- gl(3,1,9) -treatment <- gl(3,3) -d.AD <- data.frame(treatment, outcome, counts) -glm.D93 <- glm(counts ~ outcome + treatment, family = poisson) -xtable(glm.D93, align = "r|llrc") -@ - \subsection{prcomp} <>= pr1 <- prcomp(USArrests) @@ -173,8 +104,7 @@ xtable(summary(pr1)) temp.ts <- ts(cumsum(1 + round(rnorm(100), 0)), start = c(1954, 7), frequency = 12) temp.table <- xtable(temp.ts, digits = 0) -caption(temp.table) <- "Time series example" -print(temp.table, floating = TRUE) +temp.table @ <>= @@ -197,6 +127,8 @@ print(temp.table, floating = TRUE) # } @ +\newpage + \section{Helper functions for formatting} The functions \code{xalign}, \code{xdigits}, and \code{xdisplay} are useful for formatting tables in a sensible way. Consider the output produced by the default @@ -238,7 +170,7 @@ xtable(insane) Sometimes you might want to have your own sanitization function. <>= -wanttex <- xtable(data.frame(label = +wanttex <- xtable(data.frame(Column = paste("Value_is $10^{-",1:3,"}$", sep = ""))) print(wanttex, sanitize.text.function = function(str) gsub("_", "\\_", str, fixed = TRUE)) @@ -253,7 +185,7 @@ a custom \code{sanitize.text.function}. <>= mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4) rownames(mat) <- "$y_{t-1}$" -colnames(mat) <- c("$R^2$", "$\\bar{R}^2$", "F-stat", "S.E.E", "DW") +colnames(mat) <- c("$R^2$", "$\\bar{x}$", "F-stat", "S.E.E", "DW") mat <- xtable(mat) print(mat, sanitize.text.function = function(x) {x}) @ @@ -275,14 +207,14 @@ print(xtable(money), sanitize.rownames.function = function(x) {x}) \section{Format examples} \subsection{Adding a centering environment} <>= -print(xtable(lm.D9, caption = "\\tt latex.environments = NULL"), - floating = TRUE, latex.environments = NULL) -print(xtable(lm.D9, caption = "\\tt latex.environments = \"\""), +print(xtable(money, caption = "\\tt latex.environments = \"\""), floating = TRUE, latex.environments = "") -print(xtable(lm.D9, caption = "\\tt latex.environments = \"center\""), +print(xtable(money, caption = "\\tt latex.environments = \"center\""), floating = TRUE, latex.environments = "center") @ +\newpage + \subsection{Column alignment} <>= tli.table <- xtable(tli[1:10, ]) @@ -328,7 +260,8 @@ tli.table \newpage -\subsection{Suppress row names} +\subsection{Suppress row/column names} +\subsubsection{Suppress row names} <>= tli.table <- xtable(tli[1:10, ]) print(tli.table, include.rownames = FALSE) @@ -350,7 +283,7 @@ align(tli.table) <- "|rr|lp{3cm}l|r|" \newpage -\subsection{Suppress column names} +\subsubsection{Suppress column names} <>= print(tli.table, include.colnames = FALSE) @ @@ -362,14 +295,14 @@ print(tli.table, include.colnames = FALSE, hline.after = c(0,nrow(tli.table))) @ -\subsection{Suppress row and column names} +\subsubsection{Suppress row and column names} <>= print(tli.table, include.colnames = FALSE, include.rownames = FALSE) @ \newpage -\subsection{Rotate row and column names} +\subsection{Rotate row/column names} The \code{rotate.rownames} and \code{rotate.colnames} arguments can be used to rotate the row and/or column names. This requires \verb|\usepackage{rotating}| in the \LaTeX\ preamble. @@ -386,7 +319,7 @@ Use the \code{hline.after} argument to specify the position of the horizontal lines. <>= -print(xtable(anova(glm.D93)), hline.after = c(1)) +print(xtable(anova(fm3)), hline.after = c(1)) @ \subsubsection{Line styles} @@ -422,9 +355,14 @@ hlines <- c(-1, 0, 1, nrow(bktbs)) print(bktbs, booktabs = TRUE, hline.after = hlines) @ -\subsection{Table-level LaTeX} +\subsection{Table level commands} +<>= +print(xtable(anova(fm3)), size = "large") +@ + +\p <>= -print(xtable(anova(glm.D93)), size = "small") +print(xtable(anova(fm3)), size = "\\setlength{\\tabcolsep}{12pt}") @ \subsection{Long tables} @@ -471,8 +409,8 @@ fairly nearby. <>= x <- x[1:30, ] -x.small <- xtable(x, label = 'tabsmall', caption = 'A sideways table') -print(x.small, floating = TRUE, floating.environment = 'sidewaystable') +x.side <- xtable(x, caption = 'A sideways table') +print(x.side, floating = TRUE, floating.environment = 'sidewaystable') @ \clearpage