Learn R Programming

agsemisc (version 1.2-1)

plotf: Plot to multiple devices

Description

Sends the same plot to one or several devices in a uniform manner. Helpful for preparing a script that can be configured to produce graphics in several different formats, e.g. small bitmaps for web pages, large bitmaps for slides, and pdf, eps or wmf for inclusion in documents.

Usage

plotf(theplot, file="plot%03d", type=c("active"),
      size=c(6,4,10,96), prepare=a.resetplotparams, ...)

Arguments

theplot
An object representing the plot. This can either be an expression such as expression(plot(x), points(pp)) or a Lattice object such as xyplot(y~x). The object will be eval-uated (if an expression
file
The basename of the file to be produced. A suitable suffix of .eps, .ps, .pdf, .png, .jpg, or .wmf, respectively, will be appended for the actual files produced. The filename is ignored for the "active" dev
type
A character vector in which each entry represents one device to be used. Allowed values are "active", "current", "eps", "ps", "pdf", "png", "jpg", "jpeg", "wmf" and they represent the use of dev.cur, dev.cur, dev.copy2eps, p
size
A numeric vector of 1 to 4 components to which missing values will be added from the default value. Components 1 and 2 are width and height (in inches) of the plot to be produced. They will be supplied to the devices' width and
prepare
A function without parameters that will be called each time after a new device has been opened and before the plot is produced.
...
All further arguments will be handed over to each(!) of the device opening functions

Value

  • invisible()

Details

The function uses on.exit to close a device correctly even if the plot function fails. png is almost always preferable to jpeg. Note that expressions can contain multiple calls by separating them with commas.

See Also

a.resetplotparams, dev.cur, dev.copy2eps, postscript, pdf, png, jpeg.

Examples

Run this code
x = runif(40)*4
  y = x + runif(40)
  plotf(expression(plot(x, y, type="p"))) # plots to active device only
  plotf(xyplot(y~x), "myplot", type=c("active", "png", "pdf"), size=c(3,3))

Run the code above in your browser using DataLab