postscript {base}R Documentation

PostScript Graphics

Description

postscript starts the graphics device driver for producing PostScript graphics.

The auxiliary function ps.options can be used to set and view (if called without arguments) default values for the arguments to postscript. It needs to be called before calling postscript, and the default values it sets can be overridden by supplying arguments to postscript.

Usage

postscript(file = ifelse(onefile, "Rplots.ps", "Rplot%03d.ps"),
           onefile = TRUE,
           paper, family, encoding, bg, fg,
           width, height, horizontal, pointsize,
           pagecentre, print.it, command)

ps.options(paper, horizontal, width, height, family, encoding,
           pointsize, bg, fg,
           onefile = TRUE, print.it = FALSE, append = FALSE,
           reset = FALSE, override.check = FALSE)
.PostScript.Options

Arguments

file a character string giving the name of the file. If it is "", the output is piped to the command given by the argument command. If it is "|cmd", the output is piped to the command given by `cmd'.
For use with onefile=FALSE give a printf format such as "Rplot%d.ps" (the default in that case).
... further options for postscript() :
paper the size of paper in the printer. The choices are "a4", "letter", "legal" and "executive" (and these can be capitalized). Also, "special" can be used, when the width and height specify the paper size. A further choice is "default", which is the default. If this is selected, the papersize is taken from the option "papersize" if that is set and to "a4" if it is unset or empty.
horizontal the orientation of the printed image, a logical. Defaults to true, that is landscape orientation.
width, height the width and height of the graphics region in inches. The default is to use the entire page less a 0.25 inch border on each side.
family the font family to be used. EITHER a single character string which must be one of "AvantGarde", "Bookman", "Courier", "Helvetica", "Helvetica-Narrow", "NewCenturySchoolbook", "Palatino" or "Times", OR a character vector of length four.
encoding the name of an encoding file. Defaults to "ISOLatin1.enc" in the `R_HOME/afm' directory, which is used if the path does not contain a path separator. An extension ".enc" can be omitted.
pointsize the default point size to be used.
bg the default background color to be used. If "white" (or a specification equivalent to white), no background is painted.
fg the default foreground color to be used.
onefile logical: if true (the default) allow multiple figures in one file. If false, generate a file name containing the page number and give EPSF header and no DocumentMedia comment.
pagecentre logical: should the device region be centred on the page: defaults to true.
print.it logical: should the file be printed when the device is closed? (This only applies if file is a real file name.)
command the command to be used for ``printing''. Defaults to option "printcmd"; this can also be selected as "default".
append logical; currently disregarded; just there for compatibility reasons.
reset, override.check logical arguments passed to check.options. See the Examples.

Details

postscript(..) opens the file file and the PostScript commands needed to plot any graphics requested are stored in that file. This file can then be printed on a suitable device to obtain hard copy.

A postscript plot can be printed via postscript in two ways.

  1. Setting print.it = TRUE causes the command given in argument command to be called with argument "file" when the device is closed. Note that the plot file is not deleted unless command arranges to delete it.
  2. file="" or file="|cmd" can be used to print using a pipe on systems that support `popen'.

The postscript produced by R is EPS (Encapsulated PostScript) compatible, and can be included into other documents, e.g. into LaTeX, using \includegraphics{<filename>}. For use in this way you will probably want to set horizontal=FALSE, onefile=FALSE, paper="special".

Most of the PostScript prologue used is taken from the R character vector .ps.prolog. This is marked in the output, and can be changed by changing that vector. (This is only advisable for PostScript experts.)

If the second form of argument "family" is used, it should be a set of four paths to Adobe Font Metric files for the regular, bold, italic and bold italic fonts to be used. If these paths do not contain the file separator, they are taken to refer to files in the R directory `R_HOME/afm'. Thus the default Helvetica family can be specified by family = c("hv______.afm", "hvb_____.afm", "hvo_____.afm", "hvbo____.afm").

It is the user's responsibility to check that suitable fonts are made available, and that they contain the needed characters when re-encoded. The fontnames used are taken from the FontName fields of the afm files. The software including the PostScript plot file should either embed the font outlines (usually from .pfb or .pfa files) or use DSC comments to instruct the print spooler to do so.

As ISOLatin1 encoding is used, - is set as a minus and not as a hyphen. Supply a hyphen (character 173) if that is what you need.

Encodings

Encodings describe which glyphs are used to display the character codes (in the range 0–255). By default R uses ISOLatin1 encoding, and the examples for text are in that encoding. However, the encoding used on machines running R may well be different, and by using the encoding argument the glyphs can be matched to encoding in use.

None of this will matter if only ASCII characters (codes 32–126) are used as all the encodings agree over that range. Some encodings are supersets of ISOLatin1, too. However, if accented and special characters do not come out as you expect, you may need to change the encoding. Three other encodings are supplied with R: "WinAnsi.enc" and "MacRoman.enc" correspond to the encodings normally used on Windows and MacOS (at least by Adobe), and "PDFDoc.enc" is the first 256 characters of the Unicode encoding, the standard for PDF.

If you change the encoding, it is your responsibility to ensure that the PostScript font contains the glyphs used . One issue here is the Euro symbol which is in the WinAnsi and MacRoman encodings but may well not be in the PostScript fonts. (It is in the URW variants; it is not in the supplied Adobe Font Metric files.)

There is one exception. Character 45 ("-") is always set as minus (its value in Adobe ISOLatin1) even though it is hyphen in the other encodings. Hyphen is available as character 173 (octal 0255) in ISOLatin1.

See Also

Devices, {check.options which is called from both ps.options and postscript}.

Examples


# open the file "foo.ps" for graphics output
postscript("foo.ps")
# produce the desired graph(s)
dev.off()              # turn off the postscript device
postscript("|lp -dlw")
# produce the desired graph(s)
dev.off()              # plot will appear on printer



stopifnot(unlist(ps.options()) == unlist(.PostScript.Options))
ps.options(bg = "pink")
str(ps.options(reset = TRUE))

### ---- error checking of arguments: ----
ps.options(width=0:12, onefile=0, bg=pi)
# override the check for 'onefile', but not the others:
str(ps.options(width=0:12, onefile=1, bg=pi,
               override.check = c(FALSE,TRUE,FALSE)))

###  ---- Use TeX's Computer Modern fonts --- 
## Only use alphanumeric chars here.
postscript(family=paste("/myfonts/afm/",
   c("cmr10", "cmbx10", "cmsl10", "cmbxsl10"), ".afm", sep=""))
## The resultant postscript file can be used by dvips provided
## font subsetting is disabled (by flag -j0)