BMP, JPEG, PNG and TIFF graphics devices
Graphics devices for BMP, JPEG, PNG and TIFF format bitmap files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
bmp(filename = "Rplot%03d.bmp", width = 480, height = 480, units = "px", pointsize = 12, bg = "white", res = NA, family = "", restoreConsole = TRUE, type = c("windows", "cairo"), antialias) jpeg(filename = "Rplot%03d.jpg", width = 480, height = 480, units = "px", pointsize = 12, quality = 75, bg = "white", res = NA, family = "", restoreConsole = TRUE, type = c("windows", "cairo"), antialias) png(filename = "Rplot%03d.png", width = 480, height = 480, units = "px", pointsize = 12, bg = "white", res = NA, family = "", restoreConsole = TRUE, type = c("windows", "cairo", "cairo-png"), antialias) tiff(filename = "Rplot%03d.tif", width = 480, height = 480, units = "px", pointsize = 12, compression = c("none", "rle", "lzw", "jpeg", "zip", "lzw+p", "zip+p"), bg = "white", res = NA, family = "", restoreConsole = TRUE, type = c("windows", "cairo"), antialias)
the name of the output file, up to 511 characters. The
page number is substituted if a C integer format is included in the
character string, as in the default, and tilde-expansion is
the width of the device.
the height of the device.
The units in which
the default pointsize of plotted text, interpreted as
big points (1/72 inch) at
the initial background colour: can be overridden by setting par("bg").
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.
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. If not specified, taken as 72 ppi to set the size of text and line widths.
A length-one character vector specifying the default
font family. The default means to use the font numbers on the
Windows GDI versions and
See the ‘Details’ section of
Should be plotting be done using Windows GDI or cairographics?
Length-one character vector.
For allowed values and their effect on fonts with
For allowed values and their effect (on fonts and lines, but not
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. The BMP format is standard on Windows, and supported by
most viewers elsewhere. TIFF is a meta-format: the default format
tiff is lossless and stores RGB values
uncompressed—such files are widely accepted, which is their main
virtue over PNG.
Windows GDI imposes limits on the size of bitmaps: these are not
documented in the SDK and may depend on the version of Windows.
It seems that
height are each limited to
2^15-1. In addition, there are limits on the total
number of pixels which depend on the graphics hardware.
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,
res ppi (default 72) is assumed.
png will use a palette if there are fewer
than 256 colours on the page, and record a 24-bit RGB file otherwise.
type = "cairo" does the PNG output in
the driver and so is compatible with the
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 semi-transparent
png(type = "windows") supports transparent backgrounds on 16-bit
(‘High Color’) or better screens: use
"transparent". There is also support for semi-transparent colours
of lines, fills and text. However, as there is only partial support
for transparency in the graphics toolkit used: if there is a
transparent background semi-transparent colours are painted onto a
slightly off-white background and hence the pixels are opaque.
Not all PNG viewers render files with transparency correctly.
tiff compression types
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.
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
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 devices.
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 display.
On OS X when working at the console and when R is compiled with suitable support, using Apple's Quartz plotting system.
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
fontconfigto 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 available.
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
The default font family is Arial.
Line widths are a multiple of 1/96 inch (interpreted at
resppi), with a minimum of one pixel (
type = "windows") or 0.01 (
type = "cairo").
The minimum radius of a circle is 1 pixel for
type = "windows".
Colours are interpreted by the viewing application.
type = "windows" versions of these devices effectively
plot on a hidden screen and then copy the image to the required
format. This means that they have the same colour handling as the
actual screen device, and work best if that is set to a 24-bit or
32-bit colour mode.
For high-quality plots you will probably want
"cleartype" if this is not the default on your Windows system. On
the other hand,
png(antialias = "none") will give the most
The PNG specification, http://www.w3.org/TR/PNG/.
The TIFF specification, including extensions, at https://partners.adobe.com/public/developer/tiff/.
bitmap provides an alternative way to generate plots in
many bitmap formats if GhostScript is available.
1 2 3 4 5 6 7 8 9 10 11 12 13