JPlotToPDF: Plot to a PDF file

View source: R/plot_to_file.R

JPlotToPDFR Documentation

Plot to a PDF file

Description

Writes the output of a plot to a PDF file. If you are using ggplot, try either using JPlotToPDF(filename, print(<plotting code>)) or else ggsave().

Usage

JPlotToPDF(
  filename,
  plotExpr,
  width = 180,
  height = NA,
  aspectRatio = 3/2,
  units = c("mm", "cm", "in"),
  bg = "white",
  paper = "special",
  family = "Helvetica",
  onlyIfDoesntExist = FALSE,
  createDirectory = TRUE,
  cairo = FALSE,
  embedFonts = FALSE,
  ...
)

Arguments

filename

The name of the PDF to create or overwrite. If NULL, plot output goes to the current device.

plotExpr

A function or expression which will produce the plot to be written to the file.

width

The width of the output PDF file in units.

height

The height of the output PDF file in units. Defaults to width / aspectRatio. If height is specified, aspectRatio will be ignored.

aspectRatio

Aspect ratio (width / height) of the output PDF file.

units

Units of width and height.

bg

Background colour - may be "transparent" for no background.

paper

Paper size, defaults to "special" which is the value it must have if width and height are to be used. Ignored if cairo is TRUE.

family

The font family to be used. Consider using "sans", "serif" and "mono" for consistent viewing results across devices.

onlyIfDoesntExist

If TRUE and the output file already exists, JPlotToPDF will do nothing.

createDirectory

If TRUE and filename is located in a directory which doesn't exist, the directory will be created.

cairo

If TRUE, the cairo_pdf device is used, otherwise the pdf device is used (see Details).

embedFonts

If TRUE, embedFonts is called on the file after creation. This is provided as a convenience. Ghostscript must be installed and locatable (see embedFonts). I think this is unnecessary when using the Cairo PDF device.

...

Any additional arguments are passed to pdf, for example, text and font control parameters such as pointsize.

Details

The pdf argument pointsize can be specified to control the resolution of the image (as can all other arguments to pdf.)

The pdf device does not embed fonts in the pdf file. This probably does not matter if you use one of the device-independent font families, "sans", "serif" and "mono", because an appropriate (but not necessarily identical) font will be used by the viewer. Alternatively, specifying cairo = TRUE may embed the font, although the documentation for cairo_pdf is confusing.

Value

The result of evaluating plotExpr is returned invisibly (which means it is not automatically printed).

See Also

pdf, cairo_pdf, embedFonts


JimMcL/JUtils documentation built on Nov. 7, 2024, 11:25 a.m.