View source: R/textTable_methods2.bare.R
| textTable.xtable | R Documentation |
texttable from an xtable Object Create a textTable from an xtable object produced by the
xtable package. The textTable can then be styled and
plotted.
## S3 method for class 'xtable'
textTable(x, title, subtitle=character(0), foot=character(0),
row.names="", na="", mathExponents=TRUE, ...)
x |
An |
title |
Optional character vector containing title lines for the table. May be
empty ( |
subtitle, foot |
Optional character vectors providing additional annotation for the table.
May be empty (i.e., |
row.names |
A logical scalar or a character string. If FALSE, the row names of
|
na |
String to be used to represent missing values in |
mathExponents |
Logical scalar. If TRUE, then numerical values in |
... |
Additional named arguments passed to |
This function was designed based on the structure of objects produced by
version 1.8-4 of the xtable package.
An xtable object is a data frame that contains the columns of the
table and attributes that specify how those columns are to be formatted.
This function uses those attributes to created formatted character strings
for each table entry, and assembles them into a textTable object,
which may then be styled and plotted.
Formatting is done by formatC using the digits and
display attributes of x. The align attribute is used
to set the justification attributes in the returned
textTable. (Vertical rule characters, |, within
align are ignored; use an hvruleStyle or the
addHvrule function to insert vertical rules into the plotted table,
as shown in the examples.)
An object with S3 class textTable. See the documentation for the
generic for details about its structure.
# 'tli_xtab' is an 'xtable' object created using 'xtable::xtable':
class(tli_xtab)
# This package provides a 'textTable' method for such objects:
ttbl <- textTable(tli_xtab)
plot(ttbl)
if (requireNamespace("xtable", quietly=TRUE)) withAutoprint({
data(tli, package="xtable")
# ANOVA table.
fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data = tli)
plt1 <- plot(textTable(fm1.table <- xtable::xtable(fm1),
title="xtable: ANOVA table"))
# Table of linear regression results.
fm2 <- lm(tlimth ~ sex*ethnicty, data = tli)
plt2 <- plot(textTable(fm2.table <- xtable::xtable(fm2),
title="xtable: Linear regression"))
# Time series table.
temp.ts <- ts(cumsum(1 + round(rnorm(100), 0)), start = c(1954, 7),
frequency = 12)
plt3 <- plot(textTable(xtable::xtable(temp.ts, digits = 0),
title="xtable: Time series"))
# Math style for scientific notation.
plt4 <- plot(textTable(xtable::xtable(data.frame(text = c("foo","bar"),
googols = c(10e10,50e10),
small = c(8e-24,7e-5),
row.names = c("A","B")),
display = c("s","s","g","g")),
mathExponents = TRUE,
title=c("xtable:", "Math style for scientific notation")))
print(plt1, position=c(0.1, 0.9))
print(plt2, position=c(0.1, 0.5), newpage=FALSE)
print(plt3, position=c(0.1, 0.1), newpage=FALSE)
print(plt4, position=c(0.9, 0.9), newpage=FALSE)
# By default vertical rules specified by '|' characters in 'align' are
# ignored. They can be added afterward using the 'addHvrule' function
# as follows:
tli.table <- xtable::xtable(tli[1:10, ])
xtable::align(tli.table) <- "|rrl|l|lr|"
plt <- plot(textTable(tli.table,
title="xtable: Vertical rules derived from 'align'"))
pipe_posn <- which(unlist(strsplit(attr(tli.table, "align"), "")) == "|")
vrule_acol <- pipe_posn - seq_along(pipe_posn) + 0.5
for (ac in vrule_acol) plt <- addHvrule(plt, direction="vrule", acols=ac,
arows=arow(plt, "colhead_and_body"),
props=element_hvrule(linetype=1,
color="black"))
plt
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.