Package 'microplot'

Title: Microplots (Sparklines) in 'LaTeX', 'Word', 'HTML', 'Excel'
Description: The microplot function writes a set of R graphics files to be used as microplots (sparklines) in tables in either 'LaTeX', 'HTML', 'Word', or 'Excel' files. For 'LaTeX', we provide methods for the Hmisc::latex() generic function to construct 'latex' tabular environments which include the graphs. These can be used directly with the operating system 'pdflatex' or 'latex' command, or by using one of 'Sweave', 'knitr', 'rmarkdown', or 'Emacs org-mode' as an intermediary. For 'MS Word', the msWord() function uses the 'flextable' package to construct 'Word' tables which include the graphs. There are several distinct approaches for constructing HTML files. The simplest is to use the msWord() function with argument filetype="html". Alternatively, use either 'Emacs org-mode' or the htmlTable::htmlTable() function to construct an 'HTML' file containing tables which include the graphs. See the documentation for our as.htmlimg() function. For 'Excel' use on 'Windows', the file examples/irisExcel.xls includes 'VBA' code which brings the individual panels into individual cells in the spreadsheet. Examples in the examples and demo subdirectories are shown with 'lattice' graphics, 'ggplot2' graphics, and 'base' graphics. Examples for 'LaTeX' include 'Sweave' (both 'LaTeX'-style and 'Noweb'-style), 'knitr', 'emacs org-mode', and 'rmarkdown' input files and their 'pdf' output files. Examples for 'HTML' include 'org-mode' and 'Rmd' input files and their webarchive 'HTML' output files. In addition, the as.orgtable() function can display a data.frame in an 'org-mode' document. The examples for 'MS Word' (with either filetype="docx" or filetype="html") work with all operating systems. The package does not require the installation of 'LaTeX' or 'MS Word' to be able to write '.tex' or '.docx' files.
Authors: Richard M. Heiberger, with contributions from Karen Byron and Nooreen Dabbish.
Maintainer: Richard M. Heiberger <[email protected]>
License: GPL (>= 2)
Version: 1.0-45
Built: 2024-10-27 04:20:09 UTC
Source: https://github.com/cran/microplot

Help Index


Display microplots (sparklines) from R graphics panels in tables in 'LaTeX', 'Word', 'HTML', 'Excel'.

Description

The microplot function writes a set of R graphics files to be used as microplots (sparklines) in tables in either 'LaTeX', 'HTML', 'Word', or 'Excel' files. For 'LaTeX', we provide methods for the Hmisc::latex() generic function to construct 'latex' tabular environments which include the graphs. These can be used directly with the operating system 'pdflatex' or 'latex' command, or by using one of 'Sweave', 'knitr', 'rmarkdown', or 'Emacs org-mode' as an intermediary. For 'MS Word', the msWord() function uses the 'flextable' package to construct 'Word' tables which include the graphs. There are several distinct approaches for constructing HTML files. The simplest is to use the msWord() function with argument filetype="html". Alternatively, use either 'Emacs org-mode' or the htmlTable::htmlTable() function to construct an 'HTML' file containing tables which include the graphs. See the documentation for our as.htmlimg() function. For 'Excel' use on 'Windows', the file examples/irisExcel.xls includes 'VBA' code which brings the individual panels into individual cells in the spreadsheet. Examples in the examples and demo subdirectories are shown with 'lattice' graphics, 'ggplot2' graphics, and 'base' graphics. Examples for 'LaTeX' include 'Sweave' (both 'LaTeX'-style and 'Noweb'-style), 'knitr', 'emacs org-mode', and 'rmarkdown' input files and their 'pdf' output files. Examples for 'HTML' include 'org-mode' and 'Rmd' input files and their webarchive 'HTML' output files. In addition, the as.orgtable() function can display a data.frame in an 'org-mode' document. The examples for 'MS Word' (with either filetype="docx" or filetype="html") work with all operating systems. The package does not require the installation of 'LaTeX' or 'MS Word' to be able to write '.tex' or '.docx' files.

Details

The DESCRIPTION file:

Package: microplot
Type: Package
Title: Microplots (Sparklines) in 'LaTeX', 'Word', 'HTML', 'Excel'
Version: 1.0-45
Date: 2022-01-26
Author: Richard M. Heiberger, with contributions from Karen Byron and Nooreen Dabbish.
Maintainer: Richard M. Heiberger <[email protected]>
Description: The microplot function writes a set of R graphics files to be used as microplots (sparklines) in tables in either 'LaTeX', 'HTML', 'Word', or 'Excel' files. For 'LaTeX', we provide methods for the Hmisc::latex() generic function to construct 'latex' tabular environments which include the graphs. These can be used directly with the operating system 'pdflatex' or 'latex' command, or by using one of 'Sweave', 'knitr', 'rmarkdown', or 'Emacs org-mode' as an intermediary. For 'MS Word', the msWord() function uses the 'flextable' package to construct 'Word' tables which include the graphs. There are several distinct approaches for constructing HTML files. The simplest is to use the msWord() function with argument filetype="html". Alternatively, use either 'Emacs org-mode' or the htmlTable::htmlTable() function to construct an 'HTML' file containing tables which include the graphs. See the documentation for our as.htmlimg() function. For 'Excel' use on 'Windows', the file examples/irisExcel.xls includes 'VBA' code which brings the individual panels into individual cells in the spreadsheet. Examples in the examples and demo subdirectories are shown with 'lattice' graphics, 'ggplot2' graphics, and 'base' graphics. Examples for 'LaTeX' include 'Sweave' (both 'LaTeX'-style and 'Noweb'-style), 'knitr', 'emacs org-mode', and 'rmarkdown' input files and their 'pdf' output files. Examples for 'HTML' include 'org-mode' and 'Rmd' input files and their webarchive 'HTML' output files. In addition, the as.orgtable() function can display a data.frame in an 'org-mode' document. The examples for 'MS Word' (with either filetype="docx" or filetype="html") work with all operating systems. The package does not require the installation of 'LaTeX' or 'MS Word' to be able to write '.tex' or '.docx' files.
Imports: Hmisc (>= 4.1-1), HH, lattice, grid, flextable (>= 0.5-11), officer, ggplot2, htmltools, cowplot
Suggests: reshape2, latticeExtra, xtable, markdown, rmarkdown, knitr, htmlTable
License: GPL (>= 2)
NeedsCompilation: no
Packaged: 2022-01-26 21:51:27 UTC; rmh
Date/Publication: 2022-01-26 22:10:02 UTC
Repository: https://rmheiberger.r-universe.dev
RemoteUrl: https://github.com/cran/microplot
RemoteRef: HEAD
RemoteSha: 1087dbdb9055c1b5e20297678ba50b77b9fd4101

Index of help topics:

LegendrePolyMatrices    Legendre Orthogonal Polynomials for various
                        values of alpha and beta. The dataset is used
                        in the demo("LegendrePolynomials").
as.htmlimg              Place a filename or filepath in the format used
                        by HTML
as.includegraphics      Convert a filename into a complete 'LaTeX'
                        '\includegraphics' expression for use with
                        'LaTeX' '\includegraphics' macro in the
                        'graphicx' package.  This is used for 'pdf' and
                        'png' files with the system 'pdflatex' command.
                        This is used for 'ps' files with the system
                        'latex' command.
as.orgfile              Place a filename or filepath in the format used
                        by org-mode
as.orgtable             Prepare a matrix or data.frame to be used as an
                        org-mode table
cc176.y.adj             Adjusted response values and their five number
                        summaries by treatment level for one model
                        using the cc176 dataset. This dataset is used
                        in two demos: "bwplot" and "boxplot-ggplot".
dir.verify              Verifies existence of, or creates, a directory.
formatDF                Format a Data Frame or Matrix for LaTeX or
                        HTML.
graphicsList            Convert a list of "trellis" objects or list of
                        "ggplot" objects into a "graphicslist" object.
latex.AEdotplot         Display the AE (Adverse Events) dotplot of
                        incidence and relative risk from the HH package
                        in a 'LaTeX' tabular environment or in an 'MS
                        Word' or an 'HTML' table.
latex.trellis           Display a table in 'latex' containing panels
                        from R graphs in its cells.
latexSetOptions         Set the options for use of latex; check whether
                        the options for latex functions have been
                        specified.
layoutCollapse          Set the lattice 'par.settings' to remove all
                        marginal space.
microplot               Take a trellis or ggplot object, or
                        graphicsList object (list of trellis or ggplot
                        objects), and generate a set of graphics files,
                        one per panel of a multi-panel display.
microplot-package       Display microplots (sparklines) from R graphics
                        panels in tables in 'LaTeX', 'Word', 'HTML',
                        'Excel'.
microplotAttrDisplay    Specify how to display the microplots for
                        x.axis, y.axis, xlab, ylab, and key.
msWord                  Display a table in 'MS Word' containing panels
                        from R graphs in its cells.
show.latexConsole       Revisions of Hmisc latex and dvi functions that
                        display the generated latex file on screen and
                        divert the console log to a file.  New print
                        methods that display Operating System files
                        (ps, docx, html) on screen.
theme_collapse          Set the 'ggplot2' theme to remove all marginal
                        space.
toxicity                Simulated toxicity data.  Dataset is used in
                        demo("tablesPlusGraphicColumn").

Further information is available in the following vignettes:

rmhPoster Microplots in LaTeX tables, useR2016 poster (source, pdf)

Microplots are small plots that fit into the cells of a table that otherwise consists of text and numbers. A special case of a microplot is known as a sparkline.

The examples in this package show tables of simple or complex graphs placed into one or more columns of a table. The graphs can be produced by any graphical system in 'R'. We show lattice, ggplot2, and base graphics. The tables can be targeted for display in 'LaTeX', 'MS Word' on any operating system, 'MS Excel' on 'Windows', or 'HTML'. We show examples of each.

The functions produce valid 'LaTeX' .tex files or 'Word' .docx files in the working directory. If 'LaTeX' or 'Word' are installed, then the generated files can be displayed on screen as illustrated in the help file examples and the demo directory. The .tex files can be \included in a larger .tex file. Or the generated .pdf file can be displayed in ‘LaTeX’ with an \includegraphics statement. The images in the displayed .docx file can be copied and pasted into a larger 'Word' file.

The best way to learn this package is to read the examples and demo files. The primary function microplot takes a trellis or ggplot object and generates a set of graphics files, one per panel of a multi-panel display. The latex and msWprd functions place the graphics files into a table.

The latex examples (in the help file examples) and demo files use the operating system pdflatex command with the 'R' pdf() or png() graphics device. Or they could use the operating system latex command with the 'R' ps() graphics device. They therefore require that the three options
options()[c("latexcmd","dviExtension","xdvicmd")]
all be set consistently. The recommended settings for pdflatex with pdf graphics files are included as the defaults in the function call
latexSetOptions()
The recommended settings for latex with ps graphics files may be specified with the function call
latexSetOptions("latex")

Please see latexSetOptions for details on the recommended settings for use with the microplot package. See the "System options" section in the "Details" section of latex for discussion of the options themselves.

The examples in this help file are inside dontrun environments because they depend on options and they write files. You must set the options for your system before running the example manually.

Most of the 'LaTeX' examples are shown using the Hmisc::latex function latex (I am coauthor of that function). The microplot package also works with the xtable::xtable function xtable. An example in the demo directory shows a simple use of xtable.

The demos in the demo directory are not inside a dontrun environment. You must set the options for your system before running them. Each demo sets the options for pdfltex. Should you prefer latex you will need to run the demos manually. I recommend that you run the demos with ask=TRUE because will need to read them closely to see what they are doing.

To run the demos manually (with a stop at each graph), use

     demo("HowToUseMicroplot"         , package="microplot", ask=TRUE)
     demo("latex"                     , package="microplot", ask=TRUE)
     demo("latex-ggplot"              , package="microplot", ask=TRUE)
     demo("msWord"                    , package="microplot", ask=TRUE)
     demo("LegendrePolynomials"       , package="microplot", ask=TRUE)
     demo("timeseries"                , package="microplot", ask=TRUE)
     demo("NTplot"                    , package="microplot", ask=TRUE)
     demo("bwplot-lattice"            , package="microplot", ask=TRUE)
     demo("boxplot-ggplot"            , package="microplot", ask=TRUE)
     demo("tablesPlusGraphicColumn"   , package="microplot", ask=TRUE)
     demo("regrcoef"                  , package="microplot", ask=TRUE)
     demo("iris"                      , package="microplot", ask=TRUE)
     demo("AEdotplot"                 , package="microplot", ask=TRUE)
     demo("xtable"                    , package="microplot", ask=TRUE)
     demo("Examples"                  , package="microplot", ask=TRUE)
   

To run the demos automatically, with no stops, use ask=FALSE.

The examples directory system.file(package="microplot", "examples") includes complete working examples of Sweave (both LaTeX-style and Noweb-style), knitr, emacs orgmode, and rmarkdown input files and their pdf output files. These files must be copied into a directory in which you have write privilege, and that directory must be made the current working directory with setwd. They will not work from the installed package directory.

The 'Excel' for Windows example is in file examples/irisExcel.xls. The 'VBA' code in that file shows how to place the individual microplots into 'Excel' cells.

See also the vignette:
vignette("rmhPoster", package="microplot")

Author(s)

Richard M. Heiberger, with contributions from Karen Byron and Nooreen Dabbish.

Maintainer: Richard M. Heiberger <[email protected]>

See Also

latex, latex.trellis, microplot, as.includegraphics

Examples

## This example writes a set of pdf files and then uses the latex
## function to display them in LaTeX.

## The graphs are constructed three times, once each with lattice,
## base graphics, and ggplot2.

## Not run: 

  ## 0. set options for pdflatex and pdf graphics files
  latexSetOptions()


  ## 1. define dataset
  tmp <- matrix(rnorm(10), 2, 5, byrow=TRUE,
                dimnames=list(c("A", "B"), paste0("X", 1:5)))

  tmp.df <- data.frame(y=as.vector(t(tmp)),
                       group=factor(rep(row.names(tmp), each=5)))
  tmp.df


  ## 2. lattice example for latex and msWord

  tmp.lattice <- lattice::bwplot(group ~ y | " " * group, data=tmp.df, layout=c(1,2),
                                 as.table=TRUE, xlim=c(-2.1, 1.3),
                                 scales=list(y=list(relation="free", at=NULL)))
  tmp.lattice


  ## 3. using the latex.trellis method
  latex(tmp.lattice,
        height.panel=.3, width.panel=3, ## inches
        x.axis=TRUE, y.axis=FALSE,
        rowlabel="group", caption="latex.trellis of lattice graph column")

  latex(tmp.lattice, dataobject=formatDF(tmp, dec=2),
        height.panel=.3, width.panel=1.5, ## inches
        x.axis=FALSE, y.axis=FALSE,
        rowlabel="group", caption="latex.trellis of numeric data and lattice graph column")


  ## 4. MS Word example.  Uses functions in the flextable and officer packages.

  tmplw.docx <-
    msWord(tmp.lattice, dataobject=format(tmp, digits=2),
           height.panel=.3, width.panel=2, ## inches
           height.x.axis=.35, width.y.axis=.3,
           figPrefix="tmplw",
           y.axis=FALSE,
           rowlabel="group", width.rowname=.6,
           data.header="data values", width.dataobject=.6,
           graph.header="bwplot",
           caption="Lattice bwplot using msWord function")
  print.default(tmplw.docx)
  tmplw.docx  ## print method opens file
  ## cut and paste this graph into a larger .docx file.


  ## 5. ggplot2 example for latex and msWord

  library(ggplot2)

  tmpga.df <- cbind(tmp.df, fake="ff")
  tmpga <-
    ggplot(tmpga.df, aes(fake, y)) +
    geom_boxplot(outlier.size = 2) +
    facet_wrap(~ group, ncol=1) +
    coord_flip() + ylim(-2, 1.1)
  tmpga ## on interactive device


  ## 6. using the latex.ggplot method

  latex(tmpga, height.x.axis=.2, width.y.axis=.2, y.axis=FALSE)

  latex(tmpga, dataobject=formatDF(tmp, dec=2),
        height.panel=.5, height.x.axis=.2, width.y.axis=.2, y.axis=FALSE)


  ## 7. msWord with ggplot

  tmpga.docx <-
    msWord(tmpga, dataobject=format(tmp, digits=2),
           height.panel=.25, height.x.axis=.2, width.y.axis=.2, y.axis=FALSE,
           rowlabel="group", width.rowname=.6,
           data.header="data values", width.dataobject=.6,
           graph.header="bwplot",
           caption="ggplot2 boxplot using msWord function")
  print.default(tmpga.docx)
  tmpga.docx  ## print method opens file


  detach("package:ggplot2")


  ## 8. base graphics example
  ## This must be done with an explicit loop because
  ## base graphics doesn't produce a graphics object.

  dir.verify("tmpb")
  pdf("tmpb/fig%03d.pdf", onefile=FALSE, height=.5, width=3) ## inch
  par( bty="n", xaxt="n", omd=c(0,1, 0,1), mai=c(0,0,0,0))
  boxplot(tmp["A",], horizontal=TRUE, ylim=range(tmp)) ## ylim for horizontal plot
  boxplot(tmp["B",], horizontal=TRUE, ylim=range(tmp)) ## ylim for horizontal plot
  dev.off()

  tmpb.graphnames <- paste0("tmpb/fig", sprintf("%03i", 1:2), ".pdf")

  tmpb.display <-
    data.frame(round(tmp, 2),
               graphs=as.includegraphics(tmpb.graphnames, height="2em", raise="-1.4ex"))
  tmpb.display

  ## we are now using the latex.data.frame method in the Hmisc package
  tmpb.latex <- latex(tmpb.display, rowlabel="group",
                      caption="latex.default of base graphs")
  tmpb.latex$style <- "graphicx"
  tmpb.latex  ## this line requires latex in the PATH


  ## 9. detail for latex of lattice.  This is essentially what the
  ## latex.trellis method does all together.

  dir.verify("tmpl") ## create a new subdirectory of the working directory
  pdf("tmpl/fig%03d.pdf", onefile=FALSE, height=.5, width=2.5) ## inch
  update(tmp.lattice, layout=c(1,1), xlab="",
         par.settings=list(layout.heights=layoutHeightsCollapse(),
                           layout.widths=layoutWidthsCollapse(),
                           axis.line=list(col="transparent"),
                           strip.border=list(col="transparent")))
  dev.off()

  tmpl.graphnames <- paste0("tmpl/fig", sprintf("%03i", 1:2), ".pdf")
  names(tmpl.graphnames) <- rownames(tmp)

  tmpl <-
    as.includegraphics(tmpl.graphnames)
  ## retains dimensions from pdf() statement
  tmpl
  tmpl.latex <- latex(tmpl, rowlabel="group",
                      caption="latex.default of lattice graph column")
  tmpl.latex  ## this line requires latex in the PATH

  tmplw <-
    data.frame(round(tmp, 2),
               graphs=as.includegraphics(tmpl.graphnames, width="1in"))
  ## retains aspect ratio from pdf() statement
  tmplw

  tmplw.latex <- latex(tmplw, rowlabel="group",
                       caption="latex.default of numeric data and lattice graph column")
  tmplw.latex$style <- "graphicx"
  tmplw.latex  ## this line requires latex in the PATH


  ## 10. detail for latex of ggplot.
  ## left as an exercise.  It is very similar to the detail for latex with lattice.


## End(Not run)

## Please see the demos for more interesting examples.
## demo(package="microplot")

Place a filename or filepath in the format used by HTML

Description

Place a filename or filepath in the format used by HTML, by surrounding it with "<img src" and "/>" and with possible additional arguments between.

Usage

as.htmlimg(object, height = "80", width = NULL, wd = getwd(), align = "middle")

Arguments

object

Vector of character strings containing filenames.

height, width

Number of pixels as a character string.

wd

The directory in which the files reside. The default is the current working directory that R is using.

align

Specifies the alignment of an image according to surrounding elements (Not supported in HTML5). One of the strings: "top", "bottom", "middle", "left", "right"

Value

A character vector containing the input strings surrounded by "<img src" and "/>" and with possible additional arguments between.

Author(s)

Nooreen Dabbish <[email protected]> and Richard M. Heiberger <[email protected]>

See Also

microplot

Examples

as.htmlimg("abcd.png")
as.htmlimg("abcd.png", wd=".")
as.htmlimg(c("abcd.png", "efgh.png"))
cat( as.htmlimg("abcd.png")                , "\n")
cat( as.htmlimg("abcd.png", wd=".")        , "\n")
cat( paste(as.htmlimg(c("abcd.png", "efgh.png")), "\n"))

## For an example in context, please see the package example:
##    system.file(package="microplot", "examples/irisRMarkdownHtml.Rmd")
## Copy file irisRMarkdownHtml.Rmd to a directory in which you have write privileges.
## Run the statement
##   rmarkdown::render("irisRMarkdownHtml.Rmd", output_file="irisRMarkdownHtml.html")
## at the R Console.

Convert a filename into a complete 'LaTeX' \includegraphics expression for use with 'LaTeX' \includegraphics macro in the graphicx package. This is used for pdf and png files with the system pdflatex command. This is used for ps files with the system latex command.

Description

Convert a filename into a complete 'LaTeX' \includegraphics expression for use with 'LaTeX' \includegraphics macro in the graphicx package. This is used for pdf and png files with the system pdflatex command. This is used for ps files with the system latex command. The argument wd is included in the pathname in the generated expression. The \includegraphics macro is generated with the height and optional width specified by the height.includegraphics and width.includegraphics arguments; the default NULL means use the values in the graphics (pdf, png, ps) files. If either is specified, the other should be left as NULL to retain the original aspect ratio. ## An optional raise value is available for vertical alignment. An optional trim argument is available to remove excess margins from the image. See the Details section for use of the trim argument to trim panels in an externally produced graphics file.

Usage

as.includegraphics(object, ...)

## Default S3 method:
as.includegraphics(object,
           height.includegraphics=NULL, ## LaTeX measurement (character)
           width.includegraphics=NULL, ## retains original aspect ratio,
           ##                             LaTeX measurement (character)
           scale=NULL, ## number
           raise=NULL, ## LaTeX measurement (character)
           tabularinclude=TRUE,
           hspace.left=NULL,  ## LaTeX measurement (character)
           hspace.right=NULL, ## LaTeX measurement (character)
           wd=getwd(), ## working directory.  No embedded spaces in directory name.
           viewport=NULL, ## if specified, then left bottom right top (character)
           ## used for pdf png jpeg
           ## See MediaBox in pdf file.
           ## Ask operating system for png or jpg file.
           bb=NULL, ## if specified, then left bottom right top (character)
           ## used for bmp tiff ps, ask operating system for values
           trim=NULL, ## for example, "0 0 0 0" left bottom right top (character)
           x.axis.includegraphics=TRUE, ## logical or a list of arguments
           ##                              to latex \includegraphics[here]{}
           y.axis.includegraphics=TRUE, ## logical or a list of arguments
           xlab.includegraphics=FALSE,  ## logical or a list of arguments
           ylab.includegraphics=FALSE,  ## logical or a list of arguments
           key.includegraphics=!is.null(attr(object, "key.name")),
           ##                           ## logical or a list of arguments
           as.attr=FALSE, ## logical
           label.x.axis="", ## empty, nchar=0
           label.y.axis=" ", ## one space, nchar=1
           columnKey=NULL, ## see ?microplotAttrDisplay
           ...)

## S3 method for class 'microplotMatrix'
as.includegraphics(object, ...) ## principal usage.  Calls default.

## S3 method for class 'includegraphicsMatrix'
as.includegraphics(object, ...) ## returns object

## S3 method for class 'trellis'
as.includegraphics(object, ...) ## generates an informative error message.

## S3 method for class 'ggplot'
as.includegraphics(object, ...) ## generates an informative error message.

## S3 method for class 'graphicsList'
as.includegraphics(object, ...) ## generates an informative error message.

Arguments

object

A "microplotMatrix", that is a character vector or matrix of filenames for graphics files. The argument may include attributes axis.names, lab.names, and key.name for graphics files containing the "x.axis", "y.axis", "xlab", "ylab", and "key" (legend) panels.

scale

Scale factor (number) applied to figure. If either height.includegraphics or width.includegraphics is specified, then scale is ignored.

height.includegraphics, width.includegraphics

Character vector containing a LaTeX distance (by default NULL). Specifying at most one of these retains the original aspect ratio. Specifying a value for both might distort the figure by changing the aspect ratio. Specifying trim on height of a panel requires a new height to be specified to retain the aspect ratio. Specifying trim on width of a panel requires a new width to be specified to retain the aspect ratio. See demo("latex") and demo("latex-ggplot") for an example.

wd

The directory in which the files reside. The default is the full path to the current working directory that R is using. The full path is necessary when using the Hmisc::print.latex and related functions because they run the operating system's latex or pdflatex command in a temporary directory. The relative path to the current directory (wd=".") is sufficient if the file will be brought into a larger tex file with the LaTeX \input macro. Should the working directory have an embedded blank anywhere in its pathname, then as.includegraphics will generate an informative error. This is to protect you from a less-informative error that the system 'latex' command would otherwise generate. The recommended repair is to setwd() to a directory whose path has no embedded blanks anywhere. A workaround is to use wd="." in the latex call. Automatic printing with Hmisc::print.latex will not work. \input{} of the generated .tex file into your larger .tex will work. Moving the generated .tex file in the temporary directory to your working directory will work.

raise

Character vector containing a LaTeX distance (by default NULL). This value may be negative. Use it if the default vertical alignment of the graphs in the table is not satisfactory. Usually a better approach would be to use the arraystretch argument to latex.trellis.

tabularinclude

Logical. When TRUE place the generated \includegraphics{} statements inside a tabular environment. This makes the center of the included graphic align with the text on the same line of the tabular environment.

hspace.left, hspace.right

Character vector containing a LaTeX distance (by default NULL). This value may be negative. Use it if the default distance on the left or right between columns of graphs in the table is not satisfactory.

viewport

Size in pixels of the image file. This is the MediaBox in a pdf file. It is the number reported by the operating system for a png file. The viewport is optional. When specified it must be a character string containing four numbers in order: left, bottom, right, top.

bb

Bounding Box: Size in pixels of the image file. It is the number reported by the operating system for a ps file. When specified it must be a character string containing four numbers in order: left, bottom, right, top.

trim

Size in pixels to be trimmed. It must be a character string containing four numbers in order: left, bottom, right, top. See the manual for the LaTeX package graphicx for details. When trim is used, either height.includegraphics or width.includegraphics will also need to be changed. See demo("latex") and demo("latex-ggplot") for an example. See the Details section for additional use of the trim argument.

x.axis.includegraphics, y.axis.includegraphics

logical, or list of arguments to nested calls to as.includegraphics.

xlab.includegraphics, ylab.includegraphics, key.includegraphics

logical, or list of arguments to nested calls to as.includegraphics.

as.attr

Logical. When TRUE the attributes in the "microplotMatrix" argument become attributes in the "includegraphicsMatrix" result. When FALSE, the label.x.axis, label.y.axis, and columnKey arguments are passed through to microplotAttrDisplay.

label.x.axis, label.y.axis

Labels that will used by microplotAttrDisplay in the column name of the y.axis and the y.axis position for the x.axis in the 'latex' display of the graphic.

columnKey

If as.attr is FALSE and the key in attr(object, "key.name") is non-null, then microplotAttrDisplay will place its key.name as a new last value in the specified columns. The column numbering is with respect to the input object, before the y.axis or ylab are evaluated.

...

Other arguments currently ignored.

Details

We recommend that the aspect ratio be controlled by the 'R' functions that generated the figure. as.includegraphics will use the height and width values that are encoded in the pdf, png, ps files. If you need to change the size of the image we recommend that at most one of height.includegraphics and width.includegraphics be used in as.includegraphics. Using both will change the aspect ratio and consequently stretch the figure. The trim argument is used to remove excess margins from the figure; when trim is specified for height or width, the height.includegraphics or width.includegraphics will also need to be specified to retain the aspect ratio. See demo("latex") and demo("latex-ggplot") for an example.

Either the viewport (for pdf or png files) or bb (for ps files) should be specified, not both.

The trim argument can be used to take apart an externally produced graphics file and use subsets of its area as components in a 'LaTeX' table. See the files examples/irisSweaveTakeApart.Rtex and examples/irisSweaveTakeApart-Distributed.pdf for an example.

Value

A "includegraphicsMatrix" object, a vector or matrix of 'LaTeX' expressions with the 'LaTeX' macro \includegraphics for each of the input filenames. If the input argument has axis.names or lab.names or key.name attributes, then the value will also have those attributes, enclosed in \includegraphics statements. The arguments allow different \includegraphics options for the panels, the x.axis, the y.axis, xlab, ylab, and the key (legend). The location of the files listed in the input argument attributes depends on the value of the as.attr argument. When as.attr is TRUE the object attributes will become result attributes. When as.attr is FALSE, see the microplotAttrDisplay for details.

Author(s)

Richard M. Heiberger <[email protected]>

See Also

latex.trellis, microplot, latex

Examples

as.includegraphics("abc.pdf")
## [1] "\setlength{\tabcolsep}{0pt}\begin{tabular}{c}
##      \includegraphics{/Users/rmh/Rwd/abc.def}\end{tabular}"
## attr(,"class")
## [1] "includegraphicsMatrix" "character"
## This form, with the full pathname, is required when the Hmisc::print.latex
## and related functions are used for automatic display of
## the current .tex file on screen.

as.includegraphics("abc.pdf", wd=".")
## [1] "\setlength{\tabcolsep}{0pt}\begin{tabular}{c}
##      \includegraphics{./abc.pdf}\end{tabular}"
## attr(,"class")
## [1] "includegraphicsMatrix" "character"
## This form, with the relative path, is optional when the .tex file will be
## embedded into a larger file, and will not be automatically displayed on screen.


## Please see the package documentation ?microplot for a simple example in context.

## Please see the demos for more interesting examples.
## demo(package="microplot")

Place a filename or filepath in the format used by org-mode

Description

Place a filename or filepath in the format used by org-mode, by surrounding it with "[[" and "]]".

Usage

as.orgfile(object, wd = getwd(), ...)

Arguments

object

Vector of character strings containing filenames.

wd

The directory in which the files reside. The default is the current working directory that R is using.

...

Ignored.

Value

A character vector containing the input strings surrounded by "[[" and "]]".

Author(s)

Nooreen Dabbish <[email protected]> and Richard M. Heiberger <[email protected]>

See Also

microplot

Examples

as.orgfile("abcd.png")
as.orgfile("abcd.png", wd=".")
as.orgfile(c("abcd.png", "efgh.png"))

## For an example in context, please see the package example:
##    system.file(package="microplot", "examples/irisOrgHtml.org")
## Copy file irisOrgHtml.org to a directory in which you have write privileges,
## open it in emacs, and enter
## C-c C-e b           on Macintosh
## C-c C-e ho          on Windows
## C-c C-e <something> on linux

Prepare a matrix or data.frame to be used as an org-mode table

Description

Prepare a matrix or data.frame to be used as an org-mode table. Column names are required. Row names are optional (and default to FALSE

Usage

as.orgtable(x, rownames = FALSE)

Arguments

x

Matrix or data.frame.

rownames

Logical. When FALSE (the default), the row.names are not displayed in the value. When TRUE, the row.names are displayed in the value. See the last example for details on this behavior.

Value

Vector of character strings, one item for each row of the argument x. The strings contain the markup that will make them appear as tables in an org-mode document.

Author(s)

Nooreen Dabbish <[email protected]> and Richard M. Heiberger <[email protected]>

See Also

microplot

Examples

tmp <- matrix(1:12, 3, 4, dimnames=list(letters[1:3], LETTERS[4:7]))
tmp
as.orgtable(tmp)
as.orgtable(tmp, rownames=TRUE)

tmpdf <- data.frame(tmp)
tmpdf
cat(as.orgtable(tmpdf), sep="\n")
cat(as.orgtable(tmpdf, rownames=TRUE), sep="\n")

## This example shows why row names default to FALSE.

tmp2 <- rbind(tmp, tmp)
tmp2
tmp2df <- data.frame(tmp2)
tmp2df

tmp2df <- cbind(" "=row.names(tmp2), group=rep(c("A","B"), each=3), tmp2df)
tmp2df

cat(as.orgtable(tmp2df), sep="\n")  ## this is what we want

## this has the unwanted initial column of 1:6
cat(as.orgtable(tmp2df, rownames=TRUE), sep="\n")

Adjusted response values and their five number summaries by treatment level for one model using the cc176 dataset. This dataset is used in two demos: "bwplot" and "boxplot-ggplot".

Description

Adjusted response values and their five number summaries by treatment level for one model using the cc176 dataset. The five number summary is based on the standard deviation. This data set is used in two microplot demos:
demo("bwplot", package="microplot")
demo("boxplot-ggplot", package="microplot").
In both demos we reproduce HH2 (Heiberger and Holland (2015)) Table 13.2 (page 431), consisting of a table and aligned boxplot, twice—using the 'LaTeX' tabular environment accessed through the latex and microplot functions, and using an 'MS Word' table accessed through the msWord and microplot functions. In the book we used manual alignment in the 'LaTeX' code to construct the table (see chunk 6 in the file referenced by HH::HHscriptnames(13) for the code).

Usage

data("cc176.y.adj")

Author(s)

Richard M. Heiberger <[email protected]>

References

Heiberger, Richard M. and Holland, Burt (2015). Statistical Analysis and Data Display: An Intermediate Course with Examples in R, Second Edition. Springer Texts in Statistics. Springer. ISBN 978-1-4939-2121-8. https://link.springer.com/us/book/9781493921218

Examples

## Not run: 
  ## This example is based on chunks 1, 2, 4, 6 of HH::HHscriptnames(13)
  ## It defines the data(cc176.y.adj) that is used in
  ##    demo("bwplot-lattice")  ## 5 calls to latex() and 5 calls to msWord()
  ##    demo("boxplot-ggplot")  ## 2 calls to latex() and 3 calls to msWord()

data(cc176, package="HH")
cc176.aov <- aov(wt.d ~ rep + wt.n + n.treats*minutes*current,
                 data=cc176)
cc176.y.adj <- cc176$wt.d  -
  (cc176$wt.n - mean(cc176$wt.n))*coef(cc176.aov)["wt.n"]

tmp <-
sapply(split(cc176.y.adj, cc176$current),
       function(x)
         c(min=min(x),
           "m-sd"=mean(x)-sd(x),
           mean=mean(x),
           "m+sd"=mean(x)+sd(x),
           max=max(x)))
cc176fivenumsd <- t(tmp)

save(cc176.y.adj, cc176fivenumsd, file="cc176.y.adj.rda")

## End(Not run)

Verifies existence of, or creates, a directory.

Description

Verifies existence of, or creates, a directory.

Usage

dir.verify(path)

Arguments

path

A character vector containing a single path name. See dir.exists for more detail.

Value

Logical. TRUE if the directory already exists or is newly created.

Author(s)

Richard M. Heiberger <[email protected]>

See Also

dir.exists


Format a Data Frame or Matrix for LaTeX or HTML.

Description

Format a Data Frame or Matrix for LaTeX or HTML.

Usage

formatDF(...)
## please see ?Hmisc::format.df

Arguments

...

Please see format.df for details.

Details

Alias for the Hmisc::format.df function whose name will soon be deprecated.

Value

A character matrix with character images of properly rounded x. Please see format.df for details.

Author(s)

Frank E. Harrell, Jr.,
Department of Biostatistics,
Vanderbilt University,
[email protected]

Richard M. Heiberger,
Department of Statistics,
Temple University, Philadelphia, PA.
[email protected]


Convert a list of "trellis" objects or list of "ggplot" objects into a "graphicslist" object.

Description

Convert a list of "trellis" objects or list of "ggplot" objects into a "graphicslist" object.

Usage

graphicsList(...)

Arguments

...

The list can either be a "list" object, such as list(g1, g2, g3), or the actual list g1, g2, g3. All the g* objects must be the same class, either "trellis" or "ggplot". The "list" object may be an array with dim or dimnames, with length(dim(object)) either 1 or 2. An actual list, or a "list" object with one dimension, will be coerced to a column vector of graphics objects.

Value

A "graphicsList" object which can be sent to microplot.graphicsList. See microplot.graphicsList for more discussion.

Author(s)

Richard M. Heiberger <[email protected]>

Examples

## Not run: 
  latexSetOptions()

  ## graphicsList works the same for lattice and ggplot

  ## lattice
  tt <- data.frame(x=1:3, y=4:6, g=c("A","B","A"))

  ## t1 and t2: with key
  t1 <- lattice::xyplot(y ~ x, xlim=c(0,4), ylim=c(3,7), groups=g,
                        data=tt[1:2,], pch=19, col=2:3,
                        key=list(points=list(pch=19, col=2:3), text=list(levels(tt$g))))

  t2 <- lattice::xyplot(y ~ x, xlim=c(0,4), ylim=c(3,7), groups=g,
                        data=tt[3,  ], pch=19, col=2:3,
                        key=list(points=list(pch=19, col=2:3), text=list(levels(tt$g))))

  ## collapsed panels, no key
  latex(graphicsList(t1, t2), title="glt1", width.y.axis=.4, height.x.axis=.4)

  ## collapsed panels, one key
  latex(graphicsList(t1, t2), key=t1$legend$top$args$key, title="glt2",
        width.y.axis=.4, height.x.axis=.4)

  ## uncollapsed panels, one key per panel
  latex(graphicsList(list(t1, t2)), height.panel=2, width.panel=2, collapse=FALSE, title="glt1")

  ## uncollapsed panels, one key
  latex(graphicsList(list(update(t1, legend=NULL),
                          update(t2, legend=NULL))),
        height.panel=2, width.panel=2, collapse=FALSE,
        key=t1$legend$top$args$key, title="glt4")


  ## collapsed panels, no key
  msWord(graphicsList(matrix(list(t1, t2), 2, 1, dimnames=list(c("A","B"), "c"))),
         width.rowname=.5, title="Wt1", width.y.axis=.4, height.x.axis=.4)

  ## collapsed panels, one key
  msWord(graphicsList(matrix(list(t1, t2), 2, 1, dimnames=list(c("A","B"), "c"))),
         key=t1$legend$top$args$key,
         width.rowname=.5, title="Wt2", width.y.axis=.4, height.x.axis=.4)

  ## uncollapsed panels, one key per panel
  msWord(graphicsList(matrix(list(t1, t2), 2, 1, dimnames=list(c("A","B"), "c"))),
         height.panel=2, width.panel=2, collapse=FALSE,
         width.rowname=.5, title="Wt3")

  ## uncollapsed panels, one key
  msWord(graphicsList(matrix(list(update(t1, legend=NULL),
                                  update(t2, legend=NULL)),
                             2, 1, dimnames=list(c("A","B"), "c"))),
         height.panel=2, width.panel=2, collapse=FALSE,
         key=t1$legend$top$args$key,
         width.rowname=.5, title="Wt4")


  ## ggplot
  tt <- data.frame(x=1:3, y=4:6, g=c("A","B","A"))

  library(ggplot2)

  ## g1 and g2: with key
  g1 <-
    ggplot(tt[1:2,], aes(x,y, color=g)) +
    geom_point() +
    xlim(0,4) + ylim(3,7)

  g2 <-
    ggplot(tt[3,], aes(x,y, color=g)) +
    geom_point() +
    xlim(0,4) + ylim(3,7)

  g1key <- plot_grid(get_legend(g1))

  ## collapsed panels, no key
  latex(graphicsList(g1, g2), title="glg1", width.y.axis=.2, height.x.axis=.2)

  ## collapsed panels, one key
  latex(graphicsList(g1, g2), key=g1key, title="glg2", width.y.axis=.2, height.x.axis=.2)

  ## uncollapsed panels, one key per panel
  latex(graphicsList(list(g1, g2)), height.panel=2, width.panel=2, collapse=FALSE, title="glg3")

  ## uncollapsed panels, one key
  latex(graphicsList(list(g1+theme(legend.position="none"),
                          g2+theme(legend.position="none"))),
        height.panel=2, width.panel=2, collapse=FALSE,
        key=g1key, title="glg4")

  ## collapsed panels, no key
  msWord(graphicsList(g1, g2),
         width.rowname=.5, title="Wg1", width.y.axis=.4, ## width.y.axis=.2, ## not in R CMD check
         height.x.axis=.2,
         FlexTableWidths=c(.5, .45, 1))                  ## c(.5, .25, 1)    ## not in R CMD check

  ## collapsed panels, one key                           ## ditto
  msWord(graphicsList(g1, g2), key=g1key,
         width.rowname=.5, title="Wg2", width.y.axis=.4,
         height.x.axis=.2,
         FlexTableWidths=c(.5, .45, 1))

  ## uncollapsed panels, one key per panel
  msWord(graphicsList(list(g1, g2)), height.panel=2, width.panel=2, collapse=FALSE,
         width.rowname=.5, title="Wg3")

  ## uncollapsed panels, one key
  msWord(graphicsList(list(g1+theme(legend.position="none"),
                           g2+theme(legend.position="none"))),
         height.panel=2, width.panel=2, collapse=FALSE,
         key=g1key,
         width.rowname=.5, title="Wg4")

  detach("package:ggplot2") ## can't unload


## End(Not run)

Display the AE (Adverse Events) dotplot of incidence and relative risk from the HH package in a 'LaTeX' tabular environment or in an 'MS Word' or an 'HTML' table.

Description

The AEdotplot function constructs a display of the most frequently occurring AEs (Adverse Events) in the active arm of a clinical study. The latex method takes the incidence panel and the relative risk panel from the AEdotplot and places them in a 'LaTeX' tabular environment along with the numerical table of counts, percents, and relative risks. The msWord method takes the incidence panel and the relative risk panel from the AEdotplot and places them in an 'MS Word' table along with the numerical table of counts, percents, and relative risks.

Usage

## S3 method for class 'AEdotplot'
latex(object, figPrefix = first.word(deparse(substitute(object))),
      rowlabel="Most Frequent On-Therapy Adverse Events",
      device="pdf", ...)

## S3 method for class 'AEdotplot'
msWord(object, figPrefix = first.word(deparse(substitute(object))),
       device="png",
       height.panel=.25, height.x.axis=.45,
       width.left=2, width.right=1.5,
       height.key=height.panel,
       width.dataobject=.7,
       rowlabel="Adverse Event", width.rowname=2,
       ...)

## S3 method for class 'AEdotplot'
microplot(object, figPrefix, width.left=2, width.right=1.5,
          height.panel=.2, height.x.axis=.45, ...)

Arguments

object

An "AEdotplot" object as constructed by the AEdotplot.

figPrefix

Beginning characters for names of the sequence of generated graphics files. The 'latex' macro \includegraphics requires that there be no "." in the filename basename. We replace all "." in the figPrefix by "-".

device

Forwarded to microplot.

width.left, width.right

width.left is width.panel for the Percent column and width.right is the width.panel for the Relative Risk column of the AEdotplot. See AEdotplot and microplot.

height.panel, height.x.axis, height.key

See microplot.

width.dataobject, width.rowname

See msWord.

rowlabel

See latex.trellis or msWord.

...

Additional arguments to microplot.AEdotplot are forwarded to the microplot.trellis method. Additional arguments to latex.AEdotplot are forwarded to microplot.AEdotplot and to latex. Additional arguments to msWord.AEdotplot are forwarded to microplot.AEdotplot and to msWord.

Details

The microplot.AEdotplot function does most of the work, taking apart the "AEdotplot" object and constructing from it the set of graphics files identified in a "microplotMatrix" object and collecting the numerical data into a data.frame. The "microplotMatrix" and the data.frame are returned.

The latex and msWord methods call the microplot method and then the latex or msWord generic. The msWord method has more arguments than the latex method because it doesn't pick up the height and width dimensions from the graphics (.png) files.

Value

For latex.AEdotplot, the "latex" object giving the pathname of the .tex file containing the 'LaTeX' tabular environment constructed by the latex function. For msWord.AEdotplot, the "msWordFilename" object giving the pathname of the .docx file containing the generated table constructed by the msWord.microplotMatrix function which in turn uses functions in the flextable package.

The microplot.AEdotplot method returns a list containing the "microplotMatrix" and the data.frame.

Author(s)

Richard M. Heiberger <[email protected]>

See Also

See AEdotplot and latex for details on the operation of the latex method.

Examples

## See
## demo("AEdotplot", package="microplot", ask=TRUE)

Display a table in 'latex' containing panels from R graphs in its cells.

Description

Display a table in 'latex' containing panels from R graphs in its cells. Hmisc::latex methods for "trellis", "ggplot", "graphicsList", "microplotMatrix", and "includegraphicsMatrix" objects.

Usage

## S3 method for class 'graphicsClass'
latex(  ## called by trellis, ggplot, graphicsList methods
      object,
      figPrefix=first.word(deparse(substitute(object))),
      title=figPrefix, ## subject to lazy evaluation
      ##
      ## microplot arguments
      device={
        latexcmd <- options()$latexcmd
        if (is.null(latexcmd))
          latexcmd <- "latex"
        switch(latexcmd,
               pdflatex="pdf",
               latex=,
               "postscript")
      },
      ... ## can include arguments to
      ## latex.graphicsClass,
      ## microplot,
      ## as.includegraphics,
      ## latex.includegraphicsMatrix,
      ## latex.default
      )

## S3 method for class 'trellis'
latex( ## calls latex.graphicsClass
      object=stop("trellis object is required", call. = FALSE),
      figPrefix=first.word(deparse(substitute(object))),
      title=figPrefix, ## subject to lazy evaluation
      ... ## can include arguments to
      ## latex.graphicsClass,
      ## microplot,
      ## as.includegraphics,
      ## latex.includegraphicsMatrix,
      ## latex.default
      )

## S3 method for class 'ggplot'
latex( ## calls latex.graphicsClass
      object=stop("ggplot object is required", call. = FALSE),
      figPrefix=first.word(deparse(substitute(object))),
      title=figPrefix, ## subject to lazy evaluation
      ... ## can include arguments to
      ## latex.graphicsClass,
      ## microplot,
      ## as.includegraphics,
      ## latex.includegraphicsMatrix,
      ## latex.default
      )

## S3 method for class 'graphicsList'
latex( ## calls latex.graphicsClass
      object=stop("graphicsList object is required", call. = FALSE),
      figPrefix=first.word(deparse(substitute(object))),
      title=figPrefix, ## subject to lazy evaluation
      ... ## can include arguments to
      ## latex.graphicsClass,
      ## microplot,
      ## as.includegraphics,
      ## latex.includegraphicsMatrix,
      ## latex.default
      )

## S3 method for class 'includegraphicsMatrix'
latex(
      object,
      dataobject, data.first=TRUE,
      title=first.word(deparse(substitute(object))),
      microplotMatrix=NULL,
      arraystretch=1,     ## The normal interrow space is multiplied by arraystretch,
      ##                     so changing it from its default value of 1 to 1.5 makes
      ##                     the rows 1.5 times farther apart.
      ##                     Uses the latex.default argument 'insert.top'.
      bottom.hline.raise=NULL, ## character with latex unit, for example "-10ex"
      ##        arraystretch interferes with bottom.hline.raise
      ##        Pick arraystretch first.
      bottom=if (!is.null(attr(object, "key.name")))
               attr(object, "key.name"),
      col.just.object=rep("c", ncol(object)),
      col.just.dataobject=rep("r", ncol(dataobject)),
      n.cgroup=NULL, ## generated below if cgroup is specified in ... and n.cgroup is not
      ...) ## arguments to latex.default

## S3 method for class 'microplotMatrix'
latex(object,
      title=first.word(deparse(substitute(object))),
      ...) ## all ... arguments are forwarded to both
           ## as.includegraphics and latex.includegraphicsMatrix

Arguments

object

For latex.trellis, a "trellis" object, usually a multi-panel object.

For latex.ggplot, a "ggplot" object, usually a multi-panel object.

For latex.graphicsList, a "graphicsList" object, usually a list of single panel graphics objects. All items in the list must be trellis objects or all must be ggplot objects.

For latex.microplotMatrix, a "microplotMatrix" object, the result of calling microplot on a "trellis" or "ggplot" object; a matrix of LaTeX filenames, possibly with axis.names or lab.names or key.name attributes.

For latex.includegraphicsMatrix, a "includegraphicsMatrix" object, the result of calling as.includegraphics on a "microplotMatrix" object; a matrix of LaTeX \includegraphics expressions, possibly with axis.names or lab.names or key.name attributes.

device

Function used to construct the graphics files. See microplot.

dataobject

Numeric or character matrix (or data.frame).

data.first

Logical. If TRUE, then output file will have dataobject columns first, then graphics object columns. If FALSE, then output file will have graphics object columns first, then dataobject columns.

figPrefix

See microplot.trellis. The 'latex' macro \includegraphics requires that there be no "." in the filename basename. We replace all "." in the figPrefix by "-".

title

Arguments to Hmisc::latex.

microplotMatrix

The microplotMatrix will be made an attribute of the resulting latex object.

arraystretch

The normal interrow space is multiplied by arraystretch, so changing it from its default value of 1 to 1.5 makes the rows 1.5 times farther apart. Uses the latex.default argument insert.top.

bottom.hline.raise

Character string with latex unit, for example "-10ex". arraystretch interacts with bottom.hline.raise. Pick arraystretch first.

bottom

default argument to latex.default's insert.bottom argument.

col.just.object, col.just.dataobject

Column justification. See formatDF. The default centers graph panel columns and right justifies dataobject columns because it assumes the dataobject contains formatted (hence aligned) numerical data.

n.cgroup

See latex. When cgroup is specified it always appears in .... ncgroup is an optional input here because we have enough information to generate it.

...

Arguments to microplot.trellis, microplot.ggplot, as.includegraphics, latex.includegraphicsMatrix, latex.default.

Details

The explicit result is a "latex" object containing the name of a generated .tex file in the current directory. The file contains a latex \tabular environment holding a \table. The cells of the \table contain each of the filenames wrapped in an \includegraphics expression. To get the name of the created file, you must save the returned value from the "latex" function and display it with print.default.

The print method for "latex" objects wraps the generated file in a minimal complete latex file, runs that file through the system pdflatex or latex (depending on the value of options("latexcmd")) to create a pdf file (or dvi file, depending on the value of options("dviExtension")), and displays it on the screen. To get the name of the displayed file, you must explicitly use the dvi function on the "latex" object and save the otherwise invisible return value. If it is a pdf file it can be included with an \includegraphics expression into another .tex file for use with pdflatex. If it is a dvi file it can be converted with dvips to a .ps file and included with an \includegraphics expression into another .tex file for use with latex.

Value

The value of these latex methods is a "latex" object containing two components.

file

Pathname of the generated .tex file.

style

"graphicx", indicating that the latex \usepackage{graphicx} is required

See demo/HowToUseMicroplot.r for a tutorial. See the demos in demo/latex.r and demo/latex-ggplot.r for an elaborate example.

When one of the ... arguments is file="", the generated LaTeX code is printed to standard output. See the discussion of the file argument in latex to learn how to use this feature with Sweave.

Function latex.includegraphicsMatrix takes the output of as.includegraphics as its input and returns a "latex" object. If there is a key.name attribute, then it is forwarded to latex.default as the insert.bottom argument. The result has an attribute "includegraphicsMatrix" containing its argument object and an attribute "microplotMatrix" containing the "microplotMatrix" object from which the "includegraphicsMatrix" was constructed.

Function latex.microplotMatrix takes the output of microplot as its input and forwards it to latex.includegraphicsMatrix. All ... arguments are forwarded to latex.includegraphicsMatrix. The return value is a "latex" object.

Functions latex.trellis and latex.ggplot and latex.graphicsList take their input and forward it through latex.graphicsClass to microplot and then to latex.microplotMatrix.

The print method for "latex" objects, described in dvi, is to display the latexed file on the screen at 5.5in wide by 7in tall. The dimensions can be changed by an explicit call to the dvi method with other dimensions, for example
dvi(latex(MyTrellisObject), height.panel=11, width.panel=8.5)
See an example in demo("latex", package="microplot", ask=TRUE)

The format of the screen display depends on three options described in latexSetOptions and latex.

For pdflatex normally use:
latexSetOptions("pdflatex")

For latex normally use:
latexSetOptions("latex")

Author(s)

Richard M. Heiberger <[email protected]>

See Also

latex, microplot, as.includegraphics

Examples

## See the examples in the help files, the demo files, and in the
## examples subdirectory.

## The example here shows how to locate the generated .tex file and the displayed .pdf file.
## The .tex file can be brought into a larger .tex file with an \include statement.
## The .pdf file can be brought into a larger .tex file with an \includegraphics statement.

## Not run: 
## These are the settings for my machines
## Set options for Hmisc::latex
latexSetOptions()

mpgGraph <- lattice::xyplot(mpg ~ wt, group=factor(cyl), data=mtcars,
                            xlim=c(.8, 6.2), ylim=c(9,37),
                            pch=as.character(levels(factor(mtcars$cyl))), cex=2)
mpgGraph ## on your interactive device
mpgLatex <-
  latex(mpgGraph,
        height.panel=2, width.panel=3, ## inch. pick numbers that look right to you.
        height.x.axis=.37, width.y.axis=.44,  ## inch. these require trial and error.
        height.xlab=.18, width.ylab=.27,      ## inch. these require trial and error.
        rowname=NULL,    ## suppress rownames, see ?latex
        colheads=FALSE)  ## suppress colnames, see ?latex
print.default(mpgLatex)  ## file is in your working directory
mpgPdf <- dvi(mpgLatex)
print.default(mpgPdf) ## File is in a temporary directory.
                      ## If Macintosh shows "//", replace by "/" before using.
mpgPdf


## End(Not run)
## Sweave users can bring the generated files directly into their
## document.  See the discussion of the \code{file} argument in
## \code{\link[Hmisc]{latex}} to learn how to use this feature with
## Sweave.

Set the options for use of latex; check whether the options for latex functions have been specified.

Description

Set the options for use of latex; check whether the options for latex functions have been specified: if any of
options()[c("latexcmd","dviExtension","xdvicmd")] are NULL, an error message is displayed.

Usage

latexSetOptions(
     latexcmd=c("pdflatex", "latex"),
     dviExtension={
       if (is.null(latexcmd)) NULL
       else
         switch(latexcmd,
                pdflatex="pdf",
                latex="dvi")
     },
     xdvicmd={
       if (is.null(latexcmd)) NULL ## dvips is used, .ps in wd displayed
       else
         switch(latexcmd,
                pdflatex=if (nchar(Sys.which("open")))
                           "open"      ## Macintosh, Windows, SMP linux
                         else
                           "xdg-open", ## ubuntu linux
                latex="dvips") ##
                               ## dvips  Mac, Win: .ps in wd displayed
                               ## xdvi   Mac: Quartz displays image borders
                               ##             and waits until dismissed.
                               ## xdvi   Windows: not on my machine.
                               ## yap    Windows: dvi is displayed
                               ## open   Mac: nothing happens
                               ## open   Windows: yap displays dvi
     }
     )

latexCheckOptions(...)

Arguments

latexcmd, dviExtension, xdvicmd

See latex.

...

Any arguments to latexCheckOptions are ignored.

Details

These are my recommendations (the default when no arguments are specified) for pdflatex:

    options(latexcmd="pdflatex") ## Macintosh, Windows, linux
    options(dviExtension="pdf")  ## Macintosh, Windows, linux

    if (nchar(Sys.which("open"))) {
      options(xdvicmd="open")      ## Macintosh, Windows, SMP linux
    } else {
      options(xdvicmd="xdg-open")  ## ubuntu linux
    }
  

These are my recommendations for latex (and are the settings when only the first argument is set to "latex"):

    options(latexcmd="latex")
    options(dviExtension="dvi")
    options(xdvicmd="dvips")
  

Value

For latexSetOptions, the invisible list of the options that were set by this command.

For latexCheckOptions, if any NULL options are detected, the error message is printed. If all three options have non-NULL values, NULL.

Author(s)

Richard M. Heiberger <[email protected]>

See Also

latex

Examples

## Not run: 
  latexSetOptions() ## default
  latexSetOptions("pdflatex") ## same as default
  latexSetOptions("pdflatex", "pdf", "open") ## same as default on Macintosh, Windows, SMP Unix

  latexSetOptions("latex")
  latexSetOptions("latex", "dvi", "dvips") ## same as above

  latexSetOptions(NULL)
  latexSetOptions(NULL, NULL, NULL) ## same as above

## End(Not run)

Set the lattice par.settings to remove all marginal space.

Description

Set the lattice par.settings to remove all marginal space. By default layoutHeightsCollapse and layoutWidthsCollapse set everything in layout.heights or layout.widths to 0 except for panel. The user can specify values for all the standard items in either of those items.
layoutCollapse by default sets layout=c(1,1), collapses to 0 all heights and widths except for panel, removes all labels and strip labels, and sets all axis lines to col="transparent".

Usage

layoutCollapse(x,
               xlab="",
               ylab="",
               xlab.top=NULL,
               ylab.right=NULL,
               main=NULL,
               sub=NULL,
               strip=FALSE,
               strip.left=FALSE,
               layout.heights=layoutHeightsCollapse(),
               layout.widths=layoutWidthsCollapse(),
               strip.border=list(col="transparent"),
               axis.line=list(col="transparent"),
               layout=c(1,1),
               ...)
layoutHeightsCollapse(...)
layoutWidthsCollapse(...)

Arguments

...

For layoutCollapse any argument to update.trellis.

For layoutHeightsCollapse any item name in
trellis.par.get()$layout.heights.

For layoutWidthsCollapse any item name in
trellis.par.get()$layout.widths.

x

Any "trellis" object.

xlab, ylab, xlab.top, ylab.right, main, sub

Standard xyplot arguments.

strip, strip.left, strip.border, axis.line, layout

Standard xyplot arguments.

layout.heights, layout.widths

Arguments to trellis.par.get.

Details

When very small plots are placed inside a LaTeX tabular environment, it is often helpful to suppress margins, axes, labels, titles.

Value

For layoutCollapse, a "trellis" object.

For layoutHeightsCollapse and layoutWidthsCollapse, a list which may be used as input to the par.settings argument in a lattice call.

Author(s)

Richard M. Heiberger <[email protected]>

Examples

## Not run: 
  lattice::trellis.par.get("layout.heights")
  lattice::trellis.par.get("layout.widths")
  layoutHeightsCollapse()
  layoutWidthsCollapse()
  layoutWidthsCollapse(axis.left=1)

  A <- lattice::xyplot(Sepal.Length ~ Sepal.Width | Species, data=iris)

  A                 ## one page with three panels

  layoutCollapse(A) ## three pages with one unlabeled panel on each

  layoutCollapse(A, ## one page with panels labeled by ylab
                 layout=c(1,3),
                 ylab=levels(iris$Species),
                 layout.heights=list(axis.bottom=1),
                 layout.widths=list(axis.left=1),
                 axis.line=list(col="green"))

## End(Not run)

## Please see the package documentation for a simple example in context.

## Please see the demos for more interesting examples.
## demo(package="microplot")

Legendre Orthogonal Polynomials for various values of alpha and beta. The dataset is used in the demo("LegendrePolynomials").

Description

Legendre Orthogonal Polynomials for various values of alpha and beta. The dataset is used in the demo("LegendrePolynomials").

Usage

data("LegendrePolyMatrices")

Author(s)

Richard M. Heiberger <[email protected]>

Examples

## Not run: 
## dontrun is to avoid requiring the user to install the polynom and orthopolynom packages

## These matrices are used in the demo showing both latex and msWord tables
##     demo("LegendrePolynomials"       , package="microplot", ask=TRUE)

## Legendre Polynomials
if (require(orthopolynom)) {
LP.score <- function(alpha, beta, m = 4, B = 100) {
  x <- seq(1/B, 1 - 1/B, length = B)
  u <- stats::pbeta(x, alpha, beta)
  poly <-  slegendre.polynomials(m, normalized=TRUE)
  data.frame(x=x, T=sapply(poly[-1], predict, u))
}

alphas <- c(.25, .5, 1)
betas <- c(.25, .5, 1, 2, 10)


## generate LegendrePolyMatrices
LegendrePolyMatrices <- matrix(list(), nrow=length(alphas), ncol=length(betas),
                               dimnames=list(alphas=alphas, betas=betas))
for (alpha in seq(along=alphas))
   for (beta in seq(along=betas))
     LegendrePolyMatrices[[alpha, beta]] <- LP.score(alphas[alpha], betas[beta])

save(LegendrePolyMatrices, file="LegendrePolyMatrices.rda")

detach("package:orthopolynom", unload=TRUE)
detach("package:polynom", unload=TRUE)
} else data(LegendrePolyMatrices)

## End(Not run)

Take a trellis or ggplot object, or graphicsList object (list of trellis or ggplot objects), and generate a set of graphics files, one per panel of a multi-panel display.

Description

Take a trellis or ggplot object, or graphicsList object (list of trellis or ggplot objects), and generate a set of graphics files, one per panel of a multi-panel display. Additional files are generated for the axes, the axis labels, and the key.

This help file documents the microplot function. See microplot-package for information on the entire microplot package.

Usage

microplot(object, ...)

## complete for an array of lattice panels
## S3 method for class 'trellis'
microplot(
          object=stop("trellis object is required", call. = FALSE),
          ## object must have class "trellis"
          figPrefix=first.word(deparse(substitute(object))),
          vectorgraph.colname=figPrefix,
          device=c("pdf","postscript","ps","png"),
          res=600, type=getOption("bitmapType"), ## used by png
          height.panel=1, width.panel=1, ## numeric in inches
          collapse=layoutCollapse, ## Zero out unwanted
                                   ## layout.heights and layout.widths.
                                   ## See below for example.
          height.x.axis=height.panel[1],
          axis.line=list(col="black"),
          xaxis.line=axis.line,
          par.settings.x.axis=
            list(layout.heights=list(panel=0, axis.bottom=1,
                                     axis.xlab.padding=0, xlab=0),
                 axis.line=xaxis.line),
          width.y.axis=width.panel[1],
          yaxis.line=axis.line,
          par.settings.y.axis=
            list(layout.widths=list(ylab=0, ylab.axis.padding=0,
                                    axis.left=1, panel=0),
                 axis.line=yaxis.line),
          height.xlab=height.panel[1],
          par.settings.xlab=
            list(layout.heights=list(panel=0, axis.bottom=0,
                                     axis.xlab.padding=0, xlab=1),
                 axis.line=list(col="transparent")),
          width.ylab=width.panel[1],
          par.settings.ylab=
            list(layout.widths=list(ylab=1, ylab.axis.padding=0,
                                    axis.left=0, panel=0),
                 axis.line=list(col="transparent")),
          key=FALSE,    ## FALSE or a list of arguments defining a key
          height.key=height.panel[1], width.key=width.panel[1],
          ...)  ## needed to match generic.  ignored in the trellis method


## S3 method for class 'ggplot'
microplot(object, ## object has class "ggplot"
           collapse=theme_collapse(), ## theme_collapse(...) ?
           figPrefix=first.word(deparse(substitute(object))),
           vectorgraph.colname=figPrefix,
           height.panel=1, ## inch
           width.panel=1,  ## inch
           height.x.axis=height.panel,
           width.y.axis=width.panel,
           height.xlab=height.panel,
           width.ylab=width.panel,
           height.key=height.panel,
           width.key=width.panel,
           tick.text.size=7,
           key=FALSE,  ## FALSE, or a ggplot object which is a valid key
           device=c("pdf","postscript","ps","png"),
           res=600, type=getOption("bitmapType"), ## used by png
            ...)

## S3 method for class 'graphicsList'
microplot(object, ## an array of identically structured,
           ## single-panel, graphics objects (trellis or ggplot)
           ## with dim and dimnames
           figPrefix=first.word(deparse(substitute(object))),
           device=c("pdf","postscript","ps","png"),
           res=600, type=getOption("bitmapType"), ## used by png
           height.panel=1, width.panel=1, ## numeric in inches
           key=FALSE,  ## FALSE, or a trellis or ggplot object which is a valid key
           height.key=height.panel, width.key=width.panel,
           ## valid arguments for microplot.trellis or microplot.ggplot
           ...)

Arguments

object

"trellis", or "ggplot", or a graphicsList object of either all similarly constructed "trellis" objects of all similarly constructed ggplot objects.

collapse

Function that zeros out unwanted layout.heights and layout.widths space for "trellis" objects (see layoutCollapse), or that specifies a "theme" for ggplot objects (see theme_collapse).

figPrefix

Character string used as prefix for the generated files. The 'latex' macro \includegraphics requires that there be no "." in the filename basename. We replace all "." in the figPrefix by "-".

vectorgraph.colname

Character string used as column name when a vector of filenames is converted to a column matrix of filenames.

height.panel, width.panel

Height and width in inches of the generated graphics files.

height.x.axis, width.y.axis

Dimensions for axis graphics files—usually smaller than for panel contents.

height.xlab, width.ylab

Dimensions for graphics files containing axis labels—usually smaller than for panel contents.

par.settings.x.axis, par.settings.y.axis, par.settings.xlab, par.settings.ylab

"trellis" only: par.settings for axis and xlab files.

axis.line, xaxis.line, yaxis.line

"trellis" only: the usual lwd, col, cex and such that could be defined in the scales argument for xyplot.

key

Logical or list (for lattice) or ggplot object (for ggplot). If logical and FALSE there is no key (legend). If a list for microplot.trellis, it must be defined as described in xyplot for "trellis" objects. If a "ggplot" object for microplot.ggplot it must be a valid ggplot object and will be displayed in the location appropriate for a legend.

height.key, width.key

Height and width in inches of key graphics file. Defaults to same height and width as the panels.

device

Function used to construct the graphics files.

For latex with (options("latexcmd")=="pdflatex") use "pdf" (the default for pdflatex).

For latex with (options("latexcmd")=="latex") use "postscript" (the default for latex). "ps" is equivalent to "postscript".

For MSWord use "png". png defaults to res=600, type=getOption("bitmapType").

res, type

res is nominal resolution in ppi. type is either operating system-specific or "cairo". See png and cairo.

tick.text.size

Text size of the tick labels in the x and y axes (microplot.ggplot).

...

Arguments to panel function, i.e., cex and such for lattice. Similar arguments for ggplot. Currently ignored for the microplot.ggplot function.

Value

Matrix of filenames with same dim and dimnames as the argument object. The result has class "microplotMatrix". There may be one or more attributes.

axis.names

contains filenames for the x and y axes.

lab.names

contains filenames for the xlab and ylab.

key.name

contains the filename for key (legend).

Author(s)

Richard M. Heiberger <[email protected]>

See Also

latex.trellis, as.includegraphics, latex, msWord

Examples

## See demos

Specify how to display the microplots for x.axis, y.axis, xlab, ylab, and key.

Description

Specify how to display the microplots for x.axis, y.axis, xlab, ylab, and key.

Usage

microplotAttrDisplay(ii,
                     y.axis=unname(attr(ii, "axis.names")["y"]),
                     x.axis=unname(attr(ii, "axis.names")["x"]),
                     ylab=unname(attr(ii, "lab.names")["y"]),
                     xlab=unname(attr(ii, "lab.names")["x"]),
                     key=attr(ii, "key.name"),
                     columnKey=NULL,
                     label.x.axis="", ## empty, nchar=0
                     label.y.axis=" " ## one space, nchar=1
                     )

Arguments

ii

A "microplotMatrix" or "includegraphicsMatrix" of filenames of graphics files each containing one panel of an array of plots. There may be up to three attributes containing additional filenames.

x.axis, y.axis

Vector of filenames containing graphic files of axes.

label.x.axis, label.y.axis

Labels that will used in the column name of the y.axis and the y.axis column for the x.axis row in the 'latex' display of the graphic.

xlab, ylab

Vector of filenames containing graphic files of axis labels.

key

Filename containing a graphics file containing a key (legend).

columnKey

If the key is non-null, then place its filename as a new last value in the specified columns. The column numbering is with respect to the input ii before the y.axis or ylab are evaluated.

Value

Revised version of the input ii, possibly augmented with additional rows for the x.axis, xlab, and key, and additional columns for the ylab and y.axis. The xlab is ignored unless the x.axis is also specified. The ylab is ignored unless the y.axis is also specified.

Author(s)

Richard M. Heiberger <[email protected]>

See Also

microplot

Examples

## Not run: 
latexSetOptions()

filenames <-
  structure(c("tt010.pdf", "tt007.pdf", "tt004.pdf", "tt001.pdf",
              "tt011.pdf", "tt008.pdf", "tt005.pdf", "tt002.pdf",
              "tt012.pdf", "tt009.pdf", "tt006.pdf", "tt003.pdf"),
            .Dim = c(4L, 3L),
            .Dimnames = structure(list(
              rr = c("d", "c", "b", "a"),
              cc = c("E", "F", "G")),
              .Names = c("rr", "cc")),
            axis.names = structure(c("tt013.pdf", "tt014.pdf"), .Names = c("x", "y")),
            lab.names = structure(c("tt015.pdf", "tt016.pdf"), .Names = c("x", "y")),
            key.name = "tt017.pdf",
            class = c("microplotMatrix", "matrix"))

filenames

as.includegraphics(filenames, wd=".")

as.includegraphics(filenames, wd=".", as.attr=FALSE) ## default

as.includegraphics(filenames, wd=".", as.attr=TRUE)

as.includegraphics(filenames, wd=".", columnKey=1)

as.includegraphics(filenames, wd=".", columnKey=1:3)

as.includegraphics(filenames, wd=".", xlab=TRUE, ylab=TRUE)

as.includegraphics(filenames, wd=".",
                   label.x.axis="X tick values", label.y.axis="Y tick values")

tt <- data.frame(x=1:4, y=c(2,3,4,1), group=c("A","A","B","B"))
latex(lattice::xyplot(y ~ x | group, data=tt))
latex(lattice::xyplot(y ~ x | group, data=tt),
      label.x.axis="X Range", label.y.axis="Y Range")

demo("AEdotplot", package="microplot", ask=TRUE)


## End(Not run)

Display a table in 'MS Word' containing panels from R graphs in its cells.

Description

Display a table in 'MS Word' containing panels from R graphs in its cells. msWord methods for "trellis", "ggplot", "graphicsList", "microplotMatrix", and "includegraphicsMatrix" objects. The output file can be a .docx or .html file.

Usage

msWord(object, ...)

## S3 method for class 'microplotMatrix'
msWord( ## calls msWord.graphicsClass
       object, ## microplotMatrix
       ## (matrix of filenames containing individual panels)
       ## (0 columns permitted)
       filetype=c("docx","html"),
       dataobject=matrix(, nrow(object), 0), ## numeric or character matrix
       data.first=TRUE,
       title=first.word(deparse(substitute(object))),
       rowlabel=title,
       rowname=rownames(object),
       data.header="data",
       graph.header="graph",
       graph.file.directory="./",
       axis.files=attr(object,"axis.names"),
       lab.files=attr(object,"lab.names"),
       key.file=attr(object,"key.name"),
       x.axis=(!is.null(axis.files) && !is.null(axis.files["x"])),
       y.axis=(!is.null(axis.files) && !is.null(axis.files["y"])),
       xlab=FALSE,
       ylab=FALSE,
       label.x.axis="",  ## empty, nchar=0
       label.y.axis=" ", ## one space, nchar=1
       height.panel=1, ## inches
       width.panel=1, ## inches
       height.x.axis=height.panel[1], ## inches ## [1] is defensive for lazy evaluation
       width.y.axis=width.panel[1], ## inches
       height.xlab=height.panel[1], ## inches
       width.ylab=width.panel[1], ## inches
       height.key=height.panel[1], ## inches
       width.key=width.panel[1], ## inches
       FlexTableWidths=NULL, ## inches ## value used will be an attribute of result
       rmh.borders=TRUE,
       caption=NULL,
       file=paste0(title, ".", filetype),
       doc.title="Microplot",
       width.rowname=.4,
       width.dataobject=1,
       width.between=.1,
       landscape=FALSE,
       rgroup=NULL,
       n.rgroup=NULL,
       rgroup.exclude.borders=NULL,
       key.align="center",  ## flextable::align
       ...)

## S3 method for class 'graphicsClass'
msWord( ## calls msWord.graphicsClass
           object, ## called by trellis, ggplot, graphicsList methods
           ## microplot arguments
           figPrefix=first.word(deparse(substitute(object))),
           device="png",
           key=FALSE,
           title=figPrefix, ## subject to lazy evaluation
           ... ## can include arguments to
           ## microplot,
           ## msWord.microplotMatrix
           )

## S3 method for class 'trellis'
msWord( ## calls msWord.graphicsClass
           object=stop("trellis object is required", call. = FALSE),
           figPrefix=first.word(deparse(substitute(object))),
           title=figPrefix,
           ... ## can include arguments to
           ## msWord.graphicsClass,
           ## microplot,
           ## msWord.microplotMatrix
           )

## S3 method for class 'ggplot'
msWord(object=stop("ggplot object is required", call. = FALSE),
           figPrefix=first.word(deparse(substitute(object))),
           title=figPrefix,
           ... ## can include arguments to
           ## msWord.graphicsClass,
           ## microplot,
           ## msWord.microplotMatrix
           )

## S3 method for class 'graphicsList'
msWord(object=stop("graphicsList object is required", call. = FALSE),
           ## matrix or vector of trellis objects or ggplot objects,
           ## with dim and dimnames,
           ## normally each containing one panel.
           ## The axes and key will be taken from object[[1]].
           figPrefix=first.word(deparse(substitute(object))),
           title=figPrefix,
           ... ## can include arguments to
           ## msWord.graphicsClass,
           ## microplot,
           ## msWord.microplotMatrix
           )

Arguments

object

"microplotMatrix" (Matrix of filenames containing individual panels) (0 columns permitted).

filetype

File extension of generated file. Character, either "docx" or "html". For filetype="docx" the result is a variable containing the filename of a generated MS Word file. See the discussion of value below for additional information on the value. For filetype="html" the result is a variable containing a flextable object. See the discussion of value below to learn how to save the html file.

dataobject

Numeric or character matrix (or data.frame).

data.first

Logical. If TRUE, then output file will have dataobject columns first, then graphics object columns. If FALSE, then output file will have graphics object columns first, then dataobject columns.

title

Basename of generated file. We replace all "." in the title by "-".

figPrefix

See microplot.trellis. The 'latex' macro \includegraphics requires that there be no "." in the filename basename. We also enforce this requirement for msWord. We replace all "." in the figPrefix by "-".

rowlabel

Header name for column of rownames in the generated file.

rowname

Rownames of constructed table. Default is rownames of object. Specify rowname=NULL to suppress the use of row names.

data.header, graph.header

Header names for groupings of data columns and graph columns. Used when both dataobject and object are present, one of them is not missing.

graph.file.directory

Directory containing files named in object.

axis.files, lab.files, key.file

Filenames for graphics files containing axes, axis labels, and key (legend).

x.axis, xlab

Logical. If x.axis==TRUE each column of graphs will have the x.axis file placed as the last item in that column. If both are TRUE then the xlab file will be placed in the row following the x.axis file.

y.axis, ylab

Logical. If y.axis==TRUE each row of graphs will have the y.axis file placed as the first item in that row. If both are TRUE, then the ylab file will be placed on each row immediately before the y.axis file.

label.x.axis, label.y.axis

Labels that will used in the column name of the y.axis and the y.axis position for the x.axis in the 'latex' display of the graphic.

height.panel, width.panel, height.x.axis, width.y.axis, height.xlab, width.ylab

See microplot.

height.key, width.key, device, key

See microplot.

FlexTableWidths

Widths of all columns, including header and between columns, in inches. The default is to base the widths on the widths of individual columns above. The actual widths used are returned as an attribute of the returned filename. You may wish to examine these values from the first run, and then modify them on second and later runs.

rmh.borders

My preferences for borders on cells based on the American Statistical Association (https://academic.oup.com/DocumentLibrary/JSSMET/ASASTYLE_GUIDE.pdf) style sheet. The flextable default, with full borders between rows, does not conform.

caption

The table will be rendered with a numbered caption containing this string as the caption value.

file

Name of generated file.

doc.title

Title that appears in the MS Word Properties list.

width.rowname

Number of inches for the rowname column.

width.dataobject

Number of inches for each column In the data.object.

width.between

Number of inches for the column between the object (graphs) and the dataobject (numbers or text).

landscape

Logical. If TRUE then the table is produced in a landscape orientation. If FALSE, then in a portrait orientation.

rgroup, n.rgroup, rgroup.exclude.borders

Argument names borrowed from latex. rgroup gives the names of groupings of rows in the table. n.rgroup gives the number of rows within each group. rgroup.exclude.borders is not borrowed. It gives the row numbers of rows which are not to have a border between the rowname and the body of the table.

key.align

flextable::align one of left, right, center.

...

Additional arguments are currently ignored by msWord.microplotMatrix. They are forwarded to other methods by the other functions documented here.

Value

The returned value depends on the filetype argument.

For filetype="docx", the value is the name of a generated file docx file with class "msWordFilename". Printing the returned value will display the generated file on screen. The result has an attribute "microplotMatrix" containing its argument object, which contains the names of the generated microplots. The result has an attribute showing the actual FlexTableWidths used. The user may wish to use the FlexTableWidths argument on a following run to modify these values.

For filetype="html", the value is a flextable object. Printing the returned value will display the generated table in a browser window. If you wish to keep the html object, you MUST save it manually! The original file is in a temporary directory and will vanish when R is closed. Switch to the browser window and save the displayed table as a 'Web Archive' in a directory of your choice. Choose an appropriate basename for the saved file, as the default basename of the file is the noninformative "index".

Note

The msWord function uses facilities provided by the flextable and officer packages.

Author(s)

Richard M. Heiberger <[email protected]>

Examples

## See demos.

Revisions of Hmisc latex and dvi functions that display the generated latex file on screen and divert the console log to a file. New print methods that display Operating System files (ps, docx, html) on screen.

Description

Revisions of Hmisc latex and dvi functions that display the generated latex file on screen and divert the console log to a file. New functions that display Operating System files ("psFilename", "msWordFilename", or "htmlFilename") on screen.

Usage

## S3 method for class 'latexConsole'
dvi(object, prlog=FALSE, nomargins=TRUE, width=5.5, height=7, ...,
                 ConsoleToFile=TRUE)

## S3 method for class 'latexConsole'
show(object)

## S3 method for class 'dvilC'
show(object, width = 5.5, height = 7,
           ConsoleToFile=TRUE)

## S3 method for class 'OSfilename'
print(x, wait=FALSE, ...)

## S3 method for class 'OSfilename'
show(x, wait=FALSE, ...)

Arguments

object

For show.latexConsole and dvi.latexConsole, a c("latexConsole","latex") object created by latex.trellis. For show.dvilC, a c("dvilC","dvi") object created by dvi.latexConsole.

x

ConsoleToFile

Logical. TRUE diverts 'latex' and 'dvips' console output to a file (and prints the file name). FALSE displays the console output on the 'R' console.

prlog, nomargins, width, height

See latex.

x

The generic functions for print and show require x as the argument name.

wait

Logical, defaults to FALSE. Argument to system command. FALSE indicates the print should run asynchronously, meaning the R interpreter is immediately ready for the next command. With TRUE the R interpreter would wait for the command to finish.

...

ignored

Details

Extensions to 'Hmisc' functions dvi.latex, show.latex, show.dvi.

Value

For dvi.latexConsole, a c('dvilC', 'dvi') object.

For show.latexConsole and show.dvilC, when viewer="dvips" a c("psFilename", "OSfilename") object, otherwise NULL.

For print.OSfilename, the input argument is returned invisibly. For show.OSfilename, NULL.

Author(s)

Richard M. Heiberger <[email protected]>

See Also

latex, microplot-package.


Set the ggplot2 theme to remove all marginal space.

Description

Set the ggplot2 theme to remove all marginal space. By default the grid, ticks, tick labels, and axis labels are set to blank. Margins are set to 0.

Usage

theme_collapse(      ## the commented values are from theme_grey
  panel.grid.major=eb, ## element_line(colour = "white")
  panel.grid.minor=eb, ## element_line(colour = "white", size = 0.25)
  axis.ticks=eb,       ## element_line(colour = "grey20")
  axis.text=eb,        ## element_text(size = rel(0.8), colour = "grey30")
  axis.title=eb,       ## axis.title.x = element_text(
                       ##    margin = margin(t = 0.8 * half_line,
                       ##                    b = 0.8 * half_line/2))
                       ## axis.title.y = element_text(angle = 90,
                       ##    margin = margin(r = 0.8 * half_line,
                       ##                    l = 0.8 * half_line/2))
  plot.margin= grid::unit(c(0, 0, 0, 0), "in"),
  ...,
  eb=ggplot2::element_blank())

Arguments

panel.grid.major, panel.grid.minor, axis.ticks, axis.text, axis.title, plot.margin

ggplot2 theme elements. See theme for information.

...

Other valid arguments to ggplot2::theme.

eb

Convenience for ggplot2::element_blank().

Details

When very small plots are placed inside a LaTeX tabular environment, it is often helpful to suppress margins, axes, labels, titles.

Value

A ggplot2 theme object.

Note

The first draft of theme_collapse was written by Karen Byron.

Author(s)

Richard M. Heiberger <[email protected]>

Examples

theme_collapse()
## Please see the package documentation for a simple example in context.

## Please see the demos for more interesting examples.
## demo(package="microplot")

Simulated toxicity data. Dataset is used in demo("tablesPlusGraphicColumn").

Description

Simulated toxicity data. Used in demo("tablesPlusGraphicsColumn", package="microplot"). The demo shows a likert plot likert embedded in a table of numbers in both 'LaTeX' and 'MS Word'.

Usage

data("toxicity")

Format

A data frame with 4 observations on the following 5 variables.

Grade1

a numeric vector

Grade2

a numeric vector

Grade3

a numeric vector

Grade4

a numeric vector

Grade5

a numeric vector

Author(s)

Richard M. Heiberger <[email protected]>

Examples

## see demo("tablesPlusGraphicsColumn", package="microplot")