Skip to contents

Append one or more figures as content pages – image files (PNG/JPEG) or plot objects. Each figure creates one new page. Display dimensions and alignment apply to every path and plot object in figures; elements already constructed via rtfplot() keep their own settings.

Usage

rtf_figures(
  doc,
  figures,
  width_twips = NULL,
  height_twips = NULL,
  align = "center",
  titles = NULL,
  footnotes = NULL
)

Arguments

doc

An rtf_document object.

figures

A figure, or a list of them: a character file path to an image file (PNG/JPEG), a plot object (a ggplot2 plot, a patchwork, a grob, a recorded base plot, a function that draws – see rtfplot()), or a pre-built rtfplot. One figure is given as it is – rtf_figures(doc, plot) – and several as a list.

width_twips

Display width in twips of a figure that is not an rtfplot already (a file or a plot object), as rtfplot() takes it. NULL (default): the image's native size – a file at its embedded DPI, a plot object at its render_width – with no fit to the page; give a width to shrink a figure wider than the page.

height_twips

Display height in twips, as rtfplot() takes it. NULL: the native height, or – with width_twips – the height the image's aspect ratio gives.

align

Horizontal alignment for bare paths: "center" (default), "left", or "right".

titles, footnotes

Optional lists of length length(figures) or length 1 (common to all figures). See rtf_tables() for the block structure (character vectors or per-row styled lists).

Value

Modified rtf_document with appended figure contents.

Examples

png_path <- tempfile(fileext = ".png")
grDevices::png(png_path, width = 600, height = 400)
graphics::plot(1:10, main = "A figure")
grDevices::dev.off()
#> agg_record_1e953324967e 
#>                       2 
doc <- rtf_document() |>
  rtf_figures(list(png_path), width_twips = 6000L, align = "center")

# one figure, as it is: a path, or a plot object
doc <- rtf_document() |> rtf_figures(png_path)
# \donttest{
if (requireNamespace("ggplot2", quietly = TRUE)) {
  p <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point()
  doc <- rtf_document() |> rtf_figures(p)
}
# }