the name of the output file.
The page number is substituted if a C integer format is included in
the character string, as in the default. (The result must be less
than PATH_MAX characters long, and may be truncated if not.
See postscript for further details.) Tilde expansion
is performed where supported by the platform.
the width of the device.
the height of the device.
The units in which height and width are
given. Can be px (pixels, the default), in (inches),
cm or mm.
the default pointsize of plotted text, interpreted as
big points (1/72 inch) at res ppi.
the initial background colour: can be overridden by setting
the ‘quality’ of the JPEG image, as a
percentage. Smaller values will give more compression but also more
degradation of the image.
the type of compression to be used. Ignored for
type = "quartz".
The nominal resolution in ppi which will be recorded in the
bitmap file, if a positive integer. Also used for units
other than the default, and to convert points to pixels.
for type = "Xlib" only, additional arguments to
the underlying X11 device such as fonts or
For types "cairo" and "quartz", the family
argument can be supplied. See the ‘Cairo fonts’
section in the help for X11.
character string, one of "Xlib" or "quartz"
(some OS X builds) or "cairo". The latter will only be
available if the system was compiled with support for cairo –
otherwise "Xlib" will be used. The default is set by
getOption("bitmapType") – the ‘out of the box’
default is "quartz" or "cairo" where available,
for type = "cairo", giving the type of
anti-aliasing (if any) to be used for fonts and lines (but not
fills). See X11. The default is set by
X11.options. Also for type = "quartz", where
antialiasing is used unless antialias = "none".
Plots in PNG and JPEG format can easily be converted to many other
bitmap formats, and both can be displayed in modern web
browsers. The PNG format is lossless and is best for line
diagrams and blocks of colour. The JPEG format is lossy,
but may be useful for image plots, for example. BMP is a standard
format on Windows. TIFF is a meta-format: the default format written
by tiff is lossless and stores RGB (and alpha where
appropriate) values uncompressed—such files are widely accepted,
which is their main virtue over PNG.
png supports transparent backgrounds: use bg =
"transparent". (Not all PNG viewers render files with transparency
correctly.) When transparency is in use in the type = "Xlib"
variant a very light grey is used as the background and so appears as
transparent if used in the plot. This allows opaque white to be used,
as in the example. The type = "cairo", type =
"cairo-png" and type = "quartz" variants allow
semi-transparent colours, including on a transparent or
tiff with types "cairo" and "quartz" supports
semi-transparent colours, including on a transparent or
semi-transparent background. Compression type "zip" is
‘deflate (Adobe-style)’. Compression types "lzw+p" and
"zip+p" use horizontal differencing (‘differencing
predictor’, section 14 of the TIFF specification) in combination with
the compression method, which is effective for continuous-tone images,
especially colour ones.
R can be compiled without support for some or all of the types for
each of these devices: this will be reported if you attempt to use
them on a system where they are not supported. For type =
"Xlib" they may not be usable unless the X11 display is available to
the owner of the R process. type = "cairo" requires cairo 1.2
or later. type = "quartz" uses the quartz device
and so is only available where that is (on some OS X builds: see
By default no resolution is recorded in the file, except for BMP.
Viewers will often assume a nominal resolution of 72 ppi when none is
recorded. As resolutions in PNG files are recorded in pixels/metre,
the reported ppi value will be changed slightly.
For graphics parameters that make use of dimensions in inches
(including font sizes in points) the resolution used is res (or
72 ppi if unset).
png will normally use a palette if there are less than 256
colours on the page, and record a 24-bit RGB file otherwise (or a
32-bit ARGB file if type = "cairo" and non-opaque colours are
used). However, type = "cairo-png" uses cairographics' PNG
backend which will never use a palette and normally creates a larger
32-bit ARGB file—this may work better for specialist uses with
Quartz-produced PNG and TIFF plots with a transparent background are
recorded with a dark grey matte which will show up in some viewers,
including Preview on OS X.
Prior to R 3.0.3 unknown resolutions in BMP files were sometimes
recorded incorrectly: they are now recorded as 72 ppi.
A plot device is opened: nothing is returned to the R interpreter.
Note that by default the width and height values are in
pixels not inches. A warning will be issued if both are less than 20.
If you plot more than one page on one of these devices and do not
include something like %d for the sequence number in
file, the file will contain the last page plotted.
Differences between OSes
These functions are interfaces to three or more different underlying
On Windows, devices based on plotting to a hidden screen using
Windows' GDI calls.
On platforms with support for X11, plotting to a hidden X11
On OS X when working at the console and when R is
compiled with suitable support, using Apple's Quartz plotting
Where support has been compiled in for cairographics, plotting
on cairo surfaces. This may use the native platform support for
fonts, or it may use fontconfig to support a wide range of
font formats. (This was first available on Windows in R 2.14.0.)
Inevitably there will be differences between the options supported and
output produced. Perhaps the most important are support for
antialiased fonts and semi-transparent colours: the best results are
likely to be obtained with the cairo- or Quartz-based devices where
The default extensions are ‘.jpg’ and ‘.tif’ on Windows, and
‘.jpeg’ and ‘.tiff’ elsewhere.
This section describes the implementation of the conventions for
graphics devices set out in the “R Internals Manual”.
The default device size is in pixels.
Font sizes are in big points interpreted at res ppi.
The default font family is Helvetica.
Line widths in 1/96 inch (interpreted at res ppi),
minimum one pixel for type = "Xlib", 0.01 for type =
For type = "Xlib" circle radii are in pixels with
Colours are interpreted by the viewing application.
For type = "quartz" see the help for quartz.
For type = "Xlib" these devices are based on the X11
device. The colour model used will be that set up by
X11.options at the time the first Xlib-based devices was opened
(or the first after all such devices have been closed).
capabilities to see if these devices are
supported by this build of R, and if type = "cairo" is supported.
bitmap provides an alternative way to generate plots in many
bitmap formats that does not depend on accessing the X11 display but does
depend on having GhostScript installed.
## these examples will work only if the devices are available
## and cairo or an X11 display or an OS X display is available.
## copy current plot to a (large) PNG file
## Not run: dev.print(png, file = "myplot.png", width = 1024, height = 768)
png(file = "myplot.png", bg = "transparent")
rect(1, 5, 3, 7, col = "white")
## will make myplot1.jpeg and myplot2.jpeg
jpeg(file = "myplot%d.jpeg")
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> png(filename="/home/ddbj/snapshot/RGM3/R_rel/result/grDevices/png.Rd_%03d_medium.png", width=480, height=480)
> ### Name: png
> ### Title: BMP, JPEG, PNG and TIFF graphics devices
> ### Aliases: png jpeg tiff bmp
> ### Keywords: device
> ### ** Examples
> ## these examples will work only if the devices are available
> ## and cairo or an X11 display or an OS X display is available.
> ## copy current plot to a (large) PNG file
> ## Not run: dev.print(png, file = "myplot.png", width = 1024, height = 768)
> ## No test:
> #png(file = "myplot.png", bg = "transparent")
> rect(1, 5, 3, 7, col = "white")
> ## will make myplot1.jpeg and myplot2.jpeg
> jpeg(file = "myplot%d.jpeg")
rect> ## set up the plot region:
rect> op <- par(bg = "thistle")
rect> plot(c(100, 250), c(300, 450), type = "n", xlab = "", ylab = "",
rect+ main = "2 x 11 rectangles; 'rect(100+i,300+i, 150+i,380+i)'")
rect> i <- 4*(0:10)
rect> ## draw rectangles with bottom left (100, 300)+i
rect> ## and top right (150, 380)+i
rect> rect(100+i, 300+i, 150+i, 380+i, col = rainbow(11, start = 0.7, end = 0.1))
rect> rect(240-i, 320+i, 250-i, 410+i, col = heat.colors(11), lwd = i/5)
rect> ## Background alternating ( transparent / "bg" ) :
rect> j <- 10*(0:5)
rect> rect(125+j, 360+j, 141+j, 405+j/2, col = c(NA,0),
rect+ border = "gold", lwd = 2)
rect> rect(125+j, 296+j/2, 141+j, 331+j/5, col = c(NA,"midnightblue"))
rect> mtext("+ 2 x 6 rect(*, col = c(NA,0)) and col = c(NA,"m..blue"))")
rect> ## an example showing colouring and shading
rect> plot(c(100, 200), c(300, 450), type= "n", xlab = "", ylab = "")
rect> rect(100, 300, 125, 350) # transparent
rect> rect(100, 400, 125, 450, col = "green", border = "blue") # coloured
rect> rect(115, 375, 150, 425, col = par("bg"), border = "transparent")
rect> rect(150, 300, 175, 350, density = 10, border = "red")
rect> rect(150, 400, 175, 450, density = 30, col = "blue",
rect+ angle = -30, border = "transparent")
rect> legend(180, 450, legend = 1:4, fill = c(NA, "green", par("fg"), "blue"),
rect+ density = c(NA, NA, 10, 30), angle = c(NA, NA, 30, -30))
> ## End(No test)
Created & Maintained by Osamu Ogasawara (email@example.com) and