PrintFigure: Print as LaTeX Figure

Description Usage Arguments Details Value Author(s) Examples

View source: R/PrintFigure.R

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
PrintFigure(
  fig,
  nr = 1,
  nc = 1,
  label = "",
  title = "",
  title_lof = title,
  headings = "",
  pos = ""
)

Arguments

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 label argument and an index number. For example, specifying label = "id" for a figure composed of 3 subfigures results in: labels "id-1", "id-2", and "id-3".

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 fig argument. To exclude a subfigure caption specify its vector element as NA.

pos

'character' string. Placement specifiers to be used in \begin{figure}[pos]. The specifiers can consist of the following characters in any order:

  • "h" place the float about at the same point it occurs in the source text;

  • "t" position at the top of the page;

  • "b" position at the bottom of the page;

  • "p" put on a special page for floats only;

  • "!" override internal parameters LaTeX uses for determining float positions; and

  • "H" places the float at precisely the location in the source text, requires \usepackage{float} in the LaTeX preamble.

Details

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.

Value

Invisible NULL

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## 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)

inlmisc documentation built on Jan. 25, 2022, 1:14 a.m.