\documentclass{article}

\usepackage{graphicx}        % standard LaTeX graphics tool when including figure files

\newcommand{\code}[1]{{\tt #1}}

\oddsidemargin  0in
\evensidemargin 0in
\textwidth  6.5in

\begin{document}
\setkeys{Gin}{width=.25\textwidth}

This is an example of an \code{Sweave} Noweb-style file.  Run the
\code{irisNoweb.Rnw} file through \code{Sweave} to create file
\code{irisNoweb.pdf}.

Table \ref{irisBW5num} was generated by the \verb:<<iris12, echo=FALSE>>: chunk and
included in this \code{Sweave} file.

The file was run by
\begin{verbatim}
Sweave("irisNoweb.Rnw")
tools::texi2pdf("irisNoweb.tex")
system("open irisNoweb.pdf")
\end{verbatim}

<<iris12, echo=FALSE>>=
library(microplot)
library(lattice)

iris.melt <- reshape2::melt(iris, id="Species")
irisBW <- bwplot( ~ value | Species * variable, data=iris.melt)

## twelve individual boxplots without axes
irisBW.update <-
update(irisBW,
       xlab=NULL,
       par.settings=list(
         layout.heights=layoutHeightsCollapse(),
         layout.widths=layoutWidthsCollapse(),
         axis.line=list(col="transparent")),
       layout=c(1,1)
       )


pdf("irisBW%03d.pdf", onefile=FALSE, height=.4, width=1.6)  ## inch ## BB = 0 0 216 28
irisBW.update
suppress <- dev.off()

graphnames <- paste0("irisBW", sprintf("%03i", 1:12), ".pdf")

graphicsnames <- t(matrix(as.includegraphics(graphnames, height="2em", raise="-1.3ex"),
                          nrow=3, ncol=4,
                          dimnames=dimnames(irisBW)))

## Each of the twelve Species*Measurement with its five number summary
iris2 <- array(iris.melt$value, ## $
               dim=c(50, 3, 4),
               dimnames=list(NULL,
                 levels(iris.melt$Species),
                 levels(iris.melt$variable)))
iris2.fivenum <- apply(iris2, 2:3, fivenum)
dimnames(iris2.fivenum)[[1]] <- c("min", "Q1", "med", "Q3", "max")

## Species and Measurement in separate columns
BW5num <-
rbind(
data.frame(t(iris2.fivenum[,1,]), "Box Plots"=graphicsnames[,1], check.names=FALSE),
data.frame(t(iris2.fivenum[,2,]), "Box Plots"=graphicsnames[,2], check.names=FALSE),
data.frame(t(iris2.fivenum[,3,]), "Box Plots"=graphicsnames[,3], check.names=FALSE))
BW5num$Measurement=levels(iris.melt$variable)
BW5num <- BW5num[, c(7,1:6)]

BW5num.latex <- Hmisc::latex(BW5num,
                             rowname=" ",
                             rowlabel="Species",
                             rgroup=levels(iris.melt$Species),
                             n.rgroup=c(4,4,4),
                             cgroup=c("", "Five Number Summary", ""),
                             n.cgroup=c(1, 5, 1),
                             caption="Five Number Summary and Box Plots for each Species and Measurement.",
                             label="irisBW5num")
BW5num.latex$style <- "graphicx"
## BW5num.latex  ## this line requires latex in the path
## the BW5num.latex line is not needed when the file is used in a \verb:\input: statement.
@


\input{BW5num.tex}

\end{document}
