pdf
starts the graphics device driver for producing PDF
graphics.
pdf(file = ifelse(onefile, "Rplots.pdf", "Rplot%03d.pdf"), width, height, onefile, family, title, fonts, version, paper, encoding, bg, fg, pointsize, pagecentre, colormodel, useDingbats, useKerning, fillOddEven, compress)
"|cmd"
, the output is piped to the
command given by cmd
. If it is NULL
,
then no external file is created (effectively, no drawing occurs),
but the device may still be queried (e.g., for size of text). For use with onefile = FALSE
give a C integer format such
as "Rplot%03d.pdf"
(the default in that case).
(See postscript
for further details.)
Tilde expansion (see path.expand
) is done.
7
.TRUE
, and forced to true
if file
is a pipe.postscript
. Defaults to "Helvetica"
."R Graphics Output"
.NULL
."1.4"
,
but see Details."a4"
, "letter"
, "legal"
(or "us"
) and
"executive"
(and these can be capitalized), or "a4r"
and "USr"
for rotated (landscape).
The default is "special"
, which means that the width
and height
specify the paper size. A further choice is
"default"
; if this is selected, the
papersize is taken from the option "papersize"
if that is set and as "a4"
if it is unset or empty.
Defaults to "special"
.
postscript
for details. Defaults to "default"
."transparent"
."black"
.12
.paper != "special"
.
Defaults to TRUE
."srgb"
, "gray"
(or
"grey"
) and "cmyk"
. Defaults to "srgb"
. See section
Color models.TRUE
, which produces
smaller and better output. Setting this to FALSE
can work
around font display problems in broken PDF viewers: although this
font is one of the 14 guaranteed to be available in all PDF viewers,
that guarantee is not always honoured.
unix
See the Note for a possible fix for some viewers.
TRUE
.polygon
for details. Defaults to FALSE
.TRUE
."srgb"
) is sRGB. Model "gray"
(or "grey"
) maps sRGB colors to greyscale using perceived
luminosity (biased towards green). "cmyk"
outputs in CMYK
colorspace. The simplest possible conversion from sRGB to CMYK is
used
(http://en.wikipedia.org/wiki/CMYK_color_model#Mapping_RGB_to_CMYK),
and raster images are output in RGB. Also available for backwards compatibility is model "rgb"
which
uses uncalibrated RGB and corresponds to the model used with that name
in R prior to 2.13.0. Some viewers may render some plots in that
colorspace faster than in sRGB, and the plot files will be smaller.useDingbats =
FALSE
, opaque circles of less than 10 big points radius are
rendered using char 108 in the Dingbats font: all semi-transparent
and larger circles using a Bézier curve for each
quadrant.
pdf
by
something like (this is appropriate for a CUPS printing system):
pdf("|lp -o landscape", paper = "a4r")This forces
onefile = TRUE
.file
default to values given by
pdf.options()
. The ultimate defaults are quoted in the
arguments section. pdf()
opens the file file
and the PDF commands needed to
plot any graphics requested are sent to that file.
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.pdf, ..., Rplot999.pdf,
Rplot1000.pdf, ....
The family
argument can be used to specify a PDF-specific
font family as the initial/default font for the device. If additional
font families are to be used they should be included in the
fonts
argument.
If a device-independent R graphics font family is specified (e.g., via
par(family = )
in the graphics package), the PDF device makes use
of the PostScript font mappings to convert the R graphics font family
to a PDF-specific font family description. (See the
documentation for pdfFonts
.)
This device does not embed fonts in the PDF file, so it is only
straightforward to use mappings to the font families that can be
assumed to be available in any PDF viewer: "Times"
(equivalently "serif"
), "Helvetica"
(equivalently
"sans"
) and "Courier"
(equivalently "mono"
).
Other families may be specified, but it is the user's responsibility
to ensure that these fonts are available on the system and third-party
software (e.g., Ghostscript) may be required to embed the fonts so
that the PDF can be included in other documents (e.g., LaTeX): see
embedFonts
. The URW-based families described for
postscript
can be used with viewers
unix
set up to use URW fonts, which is usual with those based on
xpdf
or Ghostscript.
windows
such as GSView which utilise URW fonts.
Since embedFonts
makes use of Ghostscript, it should be
able to embed the URW-based families for use with other viewers.
See postscript
for details of encodings, as the internal
code is shared between the drivers. The native PDF encoding is given
in file PDFDoc.enc.
The PDF produced is fairly simple, with each page being represented as a single stream (by default compressed and possibly with references to raster images). The R graphics model does not distinguish graphics objects at the level of the driver interface.
The version
argument declares the version of PDF that gets
produced. The version must be at least 1.2 when compression is used,
1.4 for semi-transparent output to be understood, and at least 1.3 if
CID fonts are to be used: if any of these features are used the
version number will be increased (with a warning). (PDF 1.4 was first
supported by Acrobat 5 in 2001; it is very unlikely not to be
supported in a current viewer.)
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, which is
also the pixel size assumed for graphics parameters such as
"cra"
.
The paper
argument sets the /MediaBox entry in the file,
which defaults to width
by height
. If it is set to
something other than "special"
, a device region of the
specified size is (by default) centred on the rectangle given by the
paper size: if either width
or height
is less
than 0.1
or too large to give a total margin of 0.5 inch, it is
reset to the corresponding paper dimension minus 0.5. Thus if you
want the default behaviour of postscript
use
pdf(paper = "a4r", width = 0, height = 0)
to centre the device region
on a landscape A4 page with 0.25 inch margins.
When the background colour is fully transparent (as is the initial default value), the PDF produced does not paint the background. Most PDF viewers will use a white canvas so the visual effect is if the background were white. This will not be the case when printing onto coloured paper, though.
pdfFonts
, pdf.options
,
embedFonts
,
Devices
,
postscript
. unix
cairo_pdf
and (on OS X only) quartz
for other devices that can produce PDF.
windows
cairo_pdf
and (on OS X only) quartz
for other devices that can produce PDF.
More details of font families and encodings and especially handling text in a non-Latin-1 encoding and embedding fonts can be found in
Paul Murrell and Brian Ripley (2006) Non-standard fonts in PostScript and PDF graphics. R News, 6(2):41--47. http://cran.r-project.org/doc/Rnews/Rnews_2006-2.pdf.
## Test function for encodings
TestChars <- function(encoding = "ISOLatin1", ...)
{
pdf(encoding = encoding, ...)
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.
TestChars("ISOLatin2")
## this does not view properly in older viewers.
TestChars("ISOLatin2", family = "URWHelvetica")
## works well for viewing in gs-based viewers, and often in xpdf.
Run the code above in your browser using DataLab