Rev 26000 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{postscript}\alias{postscript}\alias{ps.options}\alias{.PostScript.Options}\alias{.ps.prolog}\title{PostScript Graphics}\description{\code{postscript} starts the graphics device driver for producingPostScript graphics.The auxiliary function \code{ps.options} can be used to set and view(if called without arguments) default values for the arguments to\code{postscript}.}\synopsis{postscript(file = ifelse(onefile, "Rplots.ps", "Rplot\%03d.ps"),onefile = TRUE, family, title = "R Graphics Output", \dots)ps.options(\dots, reset = FALSE, override.check = FALSE)}%% The definitive doc is the source :-)%% ../../../main/devices.c & ../../../unix/devPS.c\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, title = "R Graphics Output")% paper, horizontal, width, height, family, pointsize, bg, fg)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{\item{file}{a character string giving the name of the file. If it is\code{""}, the output is piped to the command given bythe argument \code{command}.#ifdef unixIf it is \code{"|cmd"}, the output is piped to the command givenby \file{cmd}.#endifFor use with \code{onefile=FALSE} give a \code{printf} format suchas \code{"Rplot\%03d.ps"} (the default in that case).}% \item{\dots}{further options for \code{postscript()}.}\item{paper}{the size of paper in the printer. The choices are\code{"a4"}, \code{"letter"}, \code{"legal"} and\code{"executive"} (and these can be capitalized).Also, \code{"special"} can be used, when the \code{width}and \code{height} specify the paper size. A further choice is\code{"default"}, which is the default. If this is selected, thepapersize is taken from the option \code{"papersize"}if that is set and to \code{"a4"} if it is unset or empty.}\item{horizontal}{the orientation of the printed image, alogical. Defaults to true, that is landscape orientation.}\item{width, height}{the width and height of the graphics region ininches. The default is to use the entire page less a 0.25 inchborder on each side.}\item{family}{the font family to be used. EITHER a single characterstring OR a character vector of lengthfour or five. See the section \sQuote{Families}.}\item{encoding}{the name of an encoding file. Defaults to#ifdef unix"ISOLatin1.enc"#endif#ifdef windows"WinAnsi.enc"#endifin the \file{R\_HOME/afm} directory, which is usedif the path does not contain a path separator. An extension\code{".enc"} can be omitted.}\item{pointsize}{the default point size to be used.}\item{bg}{the default background color to be used.If \code{"transparent"} (or an equivalent specification), nobackground is painted.}\item{fg}{the default foreground color to be used.}\item{onefile}{logical: if true (the default) allow multiple figuresin one file. If false, generate a file name containing the pagenumber and use an EPSF header and no \code{DocumentMedia} comment.}\item{pagecentre}{logical: should the device region be centred on thepage: defaults to true.}\item{print.it}{logical: should the file be printed when the device isclosed? (This only applies if \code{file} is a real file name.)}\item{command}{the command to be used for \dQuote{printing}. Defaults tooption \code{"printcmd"}; this can also be selected as\code{"default"}.}\item{append}{logical; currently \bold{disregarded}; just there forcompatibility reasons.}\item{reset, override.check}{logical arguments passed to\code{\link{check.options}}. See the Examples.}\item{title}{title string to embed in the file.}}\details{\code{postscript} opens the file \code{file} and the PostScriptcommands needed to plot any graphics requested are stored in thatfile. This file can then be printed on a suitable device to obtainhard copy.A postscript plot can be printed via \code{postscript} in two ways.\enumerate{\item Setting \code{print.it = TRUE} causes the command given inargument \code{command} to be called with argument \code{"file"}when the device is closed.Note that the plot file is not deleted unless \code{command} arranges todelete it.\item \code{file=""} or \code{file="|cmd"} can be used to printusing a pipe on systems that support \file{popen}. Failure to open thecommand will probably be reported to the terminal but not to\file{popen}, in which case close the device by \code{dev.off}immediately.}#ifdef windowsOnly the first of these will work on Windows, and the default\code{"printcmd"} is empty and will give an error if \code{print.it=TRUE}is used. Suitable commands to spool a PostScript file to a printercan be found in \file{RedMon} suite available from\url{http://www.cs.wisc.edu/~ghost/index.html}. The command will be runin a minimized window. GSView 4.x provides\file{gsprint.exe} which may be even more convenient (it requiresGhostScript version 6.0 or later).#endifThe postscript produced by \R is EPS (\emph{Encapsulated PostScript})compatible, and can be included into other documents, e.g., intoLaTeX, using \code{\includegraphics{<filename>}}. For use in this wayyou will probably want to set \code{horizontal = FALSE, onefile = FALSE,paper = "special"}.Most of the PostScript prologue used is taken from the \R charactervector \code{.ps.prolog}. This is marked in the output, and can bechanged by changing that vector. (This is only advisable forPostScript experts.)\code{ps.options} needs to be called before calling \code{postscript},and the default values it sets can be overridden by supplyingarguments to \code{postscript}.}\section{Families}{The argument \code{family} specifies the font family to be used.In normal use it is one of \code{"AvantGarde"},\code{"Bookman"}, \code{"Courier"}, \code{"Helvetica"},\code{"Helvetica-Narrow"}, \code{"NewCenturySchoolbook"},\code{"Palatino"} or \code{"Times"}, and refers to the standardAdobe PostScript fonts of those names which are included (or cloned)in all common PostScript devices.Many PostScript emulators (including those based on\code{ghostscript}) use the URW equivalents of these fonts, which are\code{"URWGothic"}, \code{"URWBookman"}, \code{"NimbusMon"},\code{"NimbusSan"}, \code{"NimbusSanCond"}, \code{"CenturySch"},\code{"URWPalladio"} and \code{"NimbusRom"} respectively. If yourPostScript device is using URW fonts, you will obtain access to morecharacters and more approriate metrics by using these names. To makethese easier to remember, \code{"URWHelvetica" == "NimbusSan"} and\code{"URWTimes" == "NimbusRom"} are also supported.It is also possible to specify \code{family="ComputerModern"}. Thisis intended to use with the Type 1 versions of the TeX CM fonts. Itwill normally be possible to include such output in TeX or LaTeXprovided it is processed with \code{dvips -Ppfb -j0} or the equivalenton your system. (\code{-j0} turns off font subsetting.)If the second form of argument \code{"family"} is used, it should be acharacter vector of four or five paths to Adobe Font Metric files forthe regular, bold, italic, bold italic and (optionally) symbol fonts tobe used. If these paths do not contain the file separator, they aretaken to refer to files in the \R directory \file{R\_HOME/afm}. Thus thedefault Helvetica family can be specified by \code{family =c("hv______.afm","hvb_____.afm", "hvo_____.afm", "hvbo____.afm", "sy______.afm")}.It is the user's responsibility to check that suitable fonts are madeavailable, and that they contain the needed characters whenre-encoded. The fontnames used are taken from the \code{FontName}fields of the afm files. The software including the PostScript plotfile should either embed the font outlines (usually from \file{.pfb}or \file{.pfa} files) or use DSC comments to instruct the printspooler to do so.}\section{Encodings}{Encodings describe which glyphs are used to display the character codes(in the range 0--255). By default \R uses ISOLatin1 encoding, andthe examples for \code{\link{text}} are in that encoding. However,the encoding used on machines running \R may well be different, and byusing the \code{encoding} argument the glyphs can be matched toencoding in use.None of this will matter if only ASCII characters (codes 32--126) areused as all the encodings agree over that range. Some encodings aresupersets of ISOLatin1, too. However, if accented and specialcharacters do not come out as you expect, you may need to change theencoding. Three other encodings are supplied with \R:\code{"WinAnsi.enc"} and \code{"MacRoman.enc"} correspond to theencodings normally used on Windows and MacOS (at least by Adobe), and\code{"PDFDoc.enc"} is the first 256 characters of the Unicodeencoding, the standard for PDF.If you change the encoding, it is your responsibility to ensure thatthe PostScript font contains the glyphs used. One issue here is the Eurosymbol which is in the WinAnsi and MacRoman encodings but may well notbe in the PostScript fonts. (It is in the URW variants; it is not inthe supplied Adobe Font Metric files.)There is one exception. Character 45 (\code{"-"}) is always setas minus (its value in Adobe ISOLatin1) even though it is hyphen inthe other encodings. Hyphen is available as character 173 (octal0255) in ISOLatin1.}\references{Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)\emph{The New S Language}.Wadsworth \& Brooks/Cole.}\seealso{\code{\link{Devices}},{\code{\link{check.options}} which is called from both\code{ps.options} and \code{postscript}}.}\author{Support for Computer Modern fonts is based on a contribution byBrian D'Urso \email{durso@hussle.harvard.edu}.}\examples{\dontrun{# open the file "foo.ps" for graphics outputpostscript("foo.ps")# produce the desired graph(s)dev.off() # turn off the postscript device#ifdef unixpostscript("|lp -dlw")# produce the desired graph(s)dev.off() # plot will appear on printer#endif#ifdef windowsoptions(printcmd='redpr -P"\\\\markov\\lw"')postscript(file=tempfile("Rps."), print.it=TRUE)# produce the desired graph(s)dev.off() # send plot file to the printer#endif# for URW PostScript devicespostscript("foo.ps", family = "NimbusSan")## for inclusion in Computer Modern TeX documents, perhapspostscript("cm_test.eps", width = 4.0, height = 3.0,horizontal = FALSE, onefile = FALSE, paper = "special",family = "ComputerModern")## The resultant postscript file can be used by dvips -Ppfb -j0.## To test out encodings, you can useTestChars <- function(encoding="ISOLatin1", family="URWHelvetica"){postscript(encoding=encoding, family=family)par(pty="s")plot(c(0,15), c(0,15), type="n", xlab="", ylab="")title(paste("Centred chars in encoding", encoding))grid(15, 15, lty=1)for(i in c(32:255)) {x <- i %% 16y <- i %/% 16points(x, y, pch=i)}dev.off()}## there will be many warnings. We use URW to get a complete enough## set of font metrics.TestChars()TestChars("ISOLatin2")TestChars("WinAnsi")}\dontshow{xx <- seq(0, 7, length=701)yy <- sin(xx)/xx; yy[1] <- 1plot(xx,yy) # produce the desired graph(s)}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)))}\keyword{device}