postscript             package:grDevices             R Documentation

_P_o_s_t_S_c_r_i_p_t _G_r_a_p_h_i_c_s

_D_e_s_c_r_i_p_t_i_o_n:

     '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'.

_U_s_a_g_e:

     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", fonts = NULL)

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

_A_r_g_u_m_e_n_t_s:

    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 of the form '"|cmd"', the output
          is piped to the command given by 'cmd'.

          For use with 'onefile = FALSE' give a 'printf' format such as
          '"Rplot%03d.ps"' (the default in that case). 

   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 on paper sizes with
          width less than height.

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
          OR a character vector of length four or five.  See the
          section 'Families'.

encoding: the name of an encoding file.  Defaults to "ISOLatin1.enc" in
          the 'afm' directory of package 'grDevices', which is used if
          the path does not contain a path separator.  An extension
          '".enc"' can be omitted. In a UTF-8 locale only
          '"ISOLatin1.enc"' is allowed. 

pointsize: the default point size to be used.

      bg: the default background color to be used. If '"transparent"'
          (or an equivalent specification), 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 use an 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.

   title: title string to embed in the file.

   fonts: a character vector specifying R graphics (device-independent)
          font family names for fonts which must be included in the
          PostScript file.

_D_e_t_a_i_l_s:

     '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'.  Failure to open the
           command will probably be reported to the terminal but not to
           'popen', in which case close the device by 'dev.off'
           immediately.

     The 'file' argument is interpreted as a C integer format as used
     by 'sprintf', with integer argument the page number. The default
     gives files 'Rplot001.ps', ..., 'Rplot999.ps', 'Rplot1000.ps',
     ....

     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: the standard version is in
     'namespace:grDevices'.)

     'ps.options' needs to be called before calling 'postscript', and
     the default values it sets can be overridden by supplying
     arguments to 'postscript'.

     A PostScript device has a default font, which can be set by the
     user via 'family'.  If other fonts are to be used when drawing to
     the PostScript device, these must be declared when the device is
     created via 'fonts';  the font family names for this argument are
     device-independent R graphics font family names (see the
     documentation for 'postscriptFonts').

     Line widths as controlled by 'par(lwd=)' are in multiples of 1/96
     inch.  Multiples less than 1 are allowed.  'pch="."' with 'cex =
     1' corresponds to a square of side 1/72 inch.

_F_a_m_i_l_i_e_s:

     Font families may be specified in several ways.  The 'family'
     argument specifies an initial/default font family for the device.
     This is a PostScript-specific font family specification (see
     below). The 'fonts' argument specifies a set of device-independent
     font families that are mapped to PostScript-specific fonts via a
     font database (see 'postscriptFonts').  

     The argument 'family' specifies the initial/default font family to
     be used.  In normal use it is one of '"AvantGarde"', '"Bookman"',
     '"Courier"', '"Helvetica"', '"Helvetica-Narrow"',
     '"NewCenturySchoolbook"', '"Palatino"' or '"Times"', and refers to
     the standard Adobe PostScript fonts families of those names which
     are included (or cloned) in all common PostScript devices.

     Many PostScript emulators (including those based on 'ghostscript')
     use the URW equivalents of these fonts, which are '"URWGothic"',
     '"URWBookman"', '"NimbusMon"', '"NimbusSan"', '"NimbusSanCond"',
     '"CenturySch"', '"URWPalladio"' and '"NimbusRom"' respectively. 
     If your PostScript device is using URW fonts, you will obtain
     access to more characters and more appropriate metrics by using
     these names.  To make these easier to remember, '"URWHelvetica" ==
     "NimbusSan"' and '"URWTimes" == "NimbusRom"' are also supported.

     If the second form of argument '"family"' is used, it should be a
     character vector of four or five paths to Adobe Font Metric files
     for the regular, bold, italic, bold italic and (optionally) symbol
     fonts to be used.  If these paths do not contain the file
     separator, they are taken to refer to files in directory 'afm' of
     package 'grDevices'. Thus the default Helvetica family can be
     specified by 'family = c("hv______.afm", "hvb_____.afm",
     "hvo_____.afm", "hvbo____.afm", "sy______.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.

     The '.afm' files for the first four fonts do not need to be in the
     correct encoding, but that for the symbol font must be.

     It is also possible to specify 'family = "ComputerModern"' with an
     appropriate encoding (see below).  This is intended to use with
     the Type 1 versions of the TeX CM fonts.  It will normally be
     possible to include such output in TeX or LaTeX provided it is
     processed with 'dvips -Ppfb -j0' or the equivalent on your system.
     ('-j0' turns off font subsetting.) When 'family =
     "ComputerModern"' is used, the italic/bold-italic fonts used are
     slanted fonts ('cmsl10' and 'cmbxsl10').  To use text italic fonts
     instead, use 'family = c("CM_regular_10.afm", "CM_boldx_10.afm",
     "cmti10.afm", "cmbxti10.afm", "CM_symbol_10.afm")'.

_E_n_c_o_d_i_n_g_s:

     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 (except '"TeXtext"') 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.  Some other encodings are
     supplied with R: '"WinAnsi.enc"' and '"MacRoman.enc"' correspond
     to the encodings normally used on Windows and Classic MacOS (at
     least by Adobe), and '"PDFDoc.enc"' is the first 256 characters of
     the Unicode encoding, the standard for PDF.  There are also
     encodings '"ISOLatin2.enc"', '"CP1250.enc"', '"ISOLatin7.enc"'
     (ISO 8859-13) and '"ISOLatin9.enc"' (ISO 8859-15),
     '"Cyrillic.enc"' (ISO 8859-5), '"KOI8-R.enc"', '"KOI8-U.enc"',
     '"CP1251.enc"', and '"TeXtext"' for the 7-bit TeX encoding.  Note
     that many glyphs in these encodings are not in the fonts
     corresponding to the standard families: the Adobe ones cover
     little more than Latin-1, whereas the URW ones also cover Latin-2,
     Latin-7, Latin-9 and Cyrillic.

     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 an 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 all the Latin encodings and Cyrillic.  There are some
     discrepancies in accounts of glyphs 39 and 96: the supplied
     encodings (except CP1250 and CP1251) treat these as 'quoteright'
     and 'quoteleft' (rather than 'quotesingle'/'acute' and 'grave'
     respectively), as they are in the Adobe documentation.

     Computer Modern fonts are encoded rather differently and should be
     used with 'encoding = "TeXtext.enc"', taking care that the symbols
     '< > \ _ { }' are not available in those fonts.

_A_u_t_h_o_r(_s):

     Support for Computer Modern fonts is based on a contribution by
     Brian D'Urso durso@hussle.harvard.edu.

_R_e_f_e_r_e_n_c_e_s:

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

_S_e_e _A_l_s_o:

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

_E_x_a_m_p_l_e_s:

     ## Not run: 
     # 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

     # for URW PostScript devices
     postscript("foo.ps", family = "NimbusSan")

     ## for inclusion in Computer Modern TeX documents, perhaps
     postscript("cm_test.eps", width = 4.0, height = 3.0,
                horizontal = FALSE, onefile = FALSE, paper = "special",
                family = "ComputerModern", encoding = "TeXtext.enc")
     ## The resultant postscript file can be used by dvips -Ppfb -j0.

     ## To test out encodings, you can use
     TestChars <- function(encoding="ISOLatin1", family="URWHelvetica")
     {
         postscript(encoding=encoding, family=family)
         par(pty="s")
         plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="", xaxs="i", yaxs="i")
         title(paste("Centred chars in encoding", encoding))
         grid(17, 17, lty=1)
         for(i in c(32:255)) {
             x <- i %% 16
             y <- i %/% 16
             points(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")
     ## End(Not run)


     ps.options(bg = "pink")
     utils::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:
     utils::str(ps.options(width=0:12, onefile=1, bg=pi,
                           override.check = c(FALSE,TRUE,FALSE)))

