JPlotToEPS: Plot to an EPS (encapsulated postscript) file

View source: R/plot_to_file.R

JPlotToEPSR Documentation

Plot to an EPS (encapsulated postscript) file

Description

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

Usage

JPlotToEPS(
  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,
  ...
)

Arguments

filename

The name of the EPS 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 EPS file in units.

height

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

aspectRatio

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

units

Units of width and height.

bg

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

paper

Paper size, defaults to "special" which is required if width and height are to be used.

family

The font family to be used. Passed to postscript.

onlyIfDoesntExist

If TRUE and the output file already exists, JPlotToEPS 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 device is used, otherwise the postscript device is used (see Details).

...

Any additional arguments are passed to postscript or cairo.

Details

R provides two mechanisms (or 'graphics devices') for writing postscript: the standard device (postscript) and the Cairo device (cairo). The cairo device is an alternative implementation for writing postscript that handles transparency, although it may output a raster bitmap rather than vector data to do so. Specify a value for the argument fallback_resolution to define the resolution of the bitmap. See cairo for details.

Value

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

See Also

postscriptFonts, postscript, cairo

Examples

## Not run: 
plotWithAlpha <- function() {
    plot(1:3, type = 'l', lwd = 20, col = "#ffcc8888")
    lines(3:1, lwd = 20, col = "#88ccff88")
}

# This will generate a warning and an empty plot due to transparency
JPlotToEPS(filename, plotWithAlpha)
# This will work (more or less) as expected
JPlotToEPS(filename, plotWithAlpha, cairo = TRUE, fallback_resolution = 600)

## End(Not run)


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