print.pltdTable: Print (Draw) a 'pltdtable' Object

Description Usage Arguments Details Value See Also Examples

View source: R/pltdTable_util.bare.R

Description

Print method for pltdTable objects, to display the table on the currently active graphics device. It draws the table at its natural size, as determined by the font size and dimensions specified by the styles used to create the table, and after applying any scale factors.

Usage

1
2
3
4
## S3 method for class 'pltdTable'
print(x, scale=NULL, newpage=TRUE, position=c(0.5, 0.5), 
    vpx=grid::unit(0.5, "npc"), vpy=grid::unit(0.5, "npc"), 
    just="center", ...)

Arguments

x

A pltdTable object, representing a table.

scale

Optional numeric multiplier used to increase or decrease the displayed size of the table, relative to the natural size implied by its styles. The default is to keep the current scaling in x.

newpage

Whether to draw the table on the current page of the graphics device, or on a new blank page.

position

Two-element numeric or character vector specifying the horizontal and vertical position of the table on the page. A value of 0 means left/bottom justification, 1 means right/top justification, and intermediate values shift the table linearly between those limits. If a character vector, valid values are "left", "center", "right" for horizontal position, and "bottom", "center", "top" for vertical position. The default is to center the table on the page.

vpx, vpy, just

Alternatives to position to specify the position of the table on the page. These are passed to grid::viewport. (vpx is passed as argument x, and vpy as argument y.) Ignored with a warning if position is specified.

...

Optional additional arguments passed to grid::viewport.

Details

The purpose of a special print method for pltdTable objects is to set a particular viewport size, so that the table is displayed at its natural size, adjusted for scale. Once the viewport is set, the table is drawn using the usual ggplot print method.

Note that scaling of table size is not cumulative. If x has already been scaled (say, by a factor of 0.8), and argument scale is set to 0.9, then the table will be displayed at 0.9 times its natural size, not 0.9*0.8 = 0.72.

The default is that the table is drawn centered in the current graphics viewport (usually the whole graphics device surface). This can be changed using either the position or the just, vpx and vpy arguments. grid::viewport uses the latter four numbers to specify position; see its documentation for details. The position argument simplifies this to use just two numbers, each in [0, 1]. It assumes one rarely wants to have parts of the table outside the boundary of the page, so 0 corresponds to putting the table snug against the left or bottom edge, 1 corresponds to putting it against the right or top edge, and intermediate values simply linearly interpolate between those limits.

Value

x, invisibly.

See Also

plot.textTable, grid::viewport, ggplot2::print.ggplot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Start with different ways of arranging the Titanic data:
data(Titanic, package="datasets")
ftbl1 <- ftable(Titanic, row.vars=c("Class", "Sex"), col.vars="Survived")
ftbl2 <- ftable(Titanic, row.vars=c("Age", "Sex", "Survived"), 
                col.vars="Class")
ftbl3 <- ftable(Titanic, row.vars=c("Sex", "Class"), 
                col.vars=c("Age", "Survived"))
plt1 <- plot(textTable(ftbl1))
plt2 <- plot(textTable(ftbl2))
plt3 <- plot(textTable(ftbl3))
plt4 <- plot(textTable(ftbl3), rowheadInside=TRUE)

# Center plots in the four quadrants of the page:
print(plt1, vpx=0.25, vpy=0.75)
print(plt2, vpx=0.75, vpy=0.75, newpage=FALSE)
print(plt3, vpx=0.25, vpy=0.25, newpage=FALSE)
print(plt4, vpx=0.75, vpy=0.25, newpage=FALSE)

# Single plot at different sizes, pushed to corners of the page:
print(plt2, scale=0.8, position=c("left", "top"))
print(plt2, scale=1.2, position=c("right", "bottom"), newpage=FALSE)
  

tablesgg documentation built on June 3, 2021, 1:06 a.m.