write1: Write a single plot to a single file (or display it)

View source: R/ggwrite.R

write1R Documentation

Write a single plot to a single file (or display it)

Description

Internal function that performs the actual device handling (opening a png/agg_png or pdf device, printing the plot, and closing the device) for a single plot/file/size combination. Also applies stamping via ggstamp before printing. If fn or type indicate on-screen display ("x11"), the plot is printed directly without opening a file device.

Usage

write1(
  plot,
  fn = NULL,
  type = NULL,
  onefile = FALSE,
  size,
  script,
  time,
  model,
  quiet = FALSE,
  subdir = NULL,
  method.png = c("ragg", "png"),
  fun.path = NULL,
  stamp.format = NULL,
  stamp.funs = NULL,
  stamp.gg.style = NULL,
  ...
)

Arguments

plot

A single plot object (ggplot, gtable, or similar).

fn

Character string, output file name (without or with extension; the extension is replaced/added based on type). NULL or "" to only display on screen.

type

Character string, one of "png", "pdf", or "x11" (display only, no file written).

onefile

Logical, passed to the pdf device via dots when writing multiple pages to a single PDF file. Not directly used for the png device.

size

A list with width and height elements (in inches), as produced by canvasSize/ggwrite_names.

script

Character string or path to the calling script, used for stamping. See ggstamp.

time

Character string or POSIXct timestamp used for stamping.

model

Character string or model object used for stamping and path construction.

quiet

Logical. If TRUE, suppresses the "Written to ..." message.

subdir

Character string, subdirectory passed on to fun.path.

method.png

Character string, one of "png" or "ragg". Controls whether png or agg_png is used as the PNG graphics device. ragg produces output that is more consistent across platforms.

fun.path

Function or character string defining output directory structure, applied to fn before the file is written. See pathFormat. If the path format uses %script, script is forwarded to it automatically (if the function accepts a script argument).

stamp.format, stamp.funs, stamp.gg.style

Passed to ggstamp.

...

Additional arguments. res is passed on to the png/ ragg device, onefile to the pdf device. A dir element (if present) is extracted but currently only used as a default working directory. A fun.path element (if present) overrides the fun.path argument.

Value

NULL, invisibly. Called for the side effect of writing a file and/or displaying the plot.

See Also

ggwrite, writeObj, ggstamp


tracee documentation built on Nov. 24, 2026, 5:07 p.m.