PrintFigure | R Documentation |
Print the LaTeX code associated with the supplied figure. A figure can be composed of several subfigures and passed to the function as R plotting commands. The applied output format attempts to adhere to the design recommendations for figures in United States Geological Survey (USGS) publications.
PrintFigure( fig, nr = 1, nc = 1, label = "", title = "", title_lof = title, headings = "", pos = "" )
fig |
'character' vector. Figure plotting commands written in R. The length of the vector is either equal to the number of subfigures, or 1 when a single plot is desired. An element in the vector contains the commands for creating a single plot. |
nr, nc |
'integer' count. Maximum number of rows and columns in the subfigure layout on a page in the output document. |
label |
'character' string.
LaTeX label anchor.
Subfigures are labeled using a concatenation of the |
title |
'character' string. Figure caption |
title_lof |
'character' string. Figure caption to be listed at the beginning of the paper in a “List of Figures”. |
headings |
'character' vector.
Subfigure captions, values are recycled as necessary
to match the vector length of the |
pos |
'character' string.
Placement specifiers to be used in
|
Requires \usepackage{caption}
and \usepackage{subcaption}
in the LaTeX preamble.
The width and height, in inches, to be used in the graphics device (that is, a single plot)
are specified in the code-chunk options fig.width
and fig.height
, respectively.
And always write raw results from R into the output document
by also specifying results = "asis"
in the code-chunk options.
Invisible NULL
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
## Not run: cat("\\documentclass{article}", "\\usepackage[labelsep=period, labelfont=bf]{caption}", "\\usepackage{subcaption}", "\\captionsetup[figure]{skip=10pt}", "\\captionsetup[subfigure]{skip=0pt, labelfont={bf, it}}", "\\renewcommand{\\thesubfigure}{\\Alph{subfigure}}", "\\begin{document}", "<<id, echo=FALSE, fig.width=3, fig.height=2, results='asis'>>=", "par(mar=c(2.1, 2.1, 1.1, 1.1))", "n <- 10", "fig <- sprintf('inlmisc::PlotGraph(runif(%s))', 2:n)", "headings <- sprintf('Subfigure caption, $n=%s$', 2:n)", "PrintFigure(fig, 3, 2, 'id', title='Caption', headings=headings)", "@", "\\end{document}", file = "test-figure.Rnw", sep = "\n") knitr::knit2pdf("test-figure.Rnw", clean = TRUE) # requires LaTeX system("open test-figure.pdf") unlink(c("test-figure.*", "figure"), recursive = TRUE) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.