agg_jpeg {ragg} | R Documentation |
Draw to a JPEG file
Description
The JPEG file format is a lossy compressed file format developed in
particular for digital photography. The format is not particularly
well-suited for line drawings and text of the type normally associated with
statistical plots as the compression algorithm creates noticable artefacts.
It is, however, great for saving image data, e.g. heightmaps etc. Thus, for
standard plots, it would be better to use agg_png()
, but for plots that
includes a high degree of raster image rendering this device will result in
smaller plots with very little quality degradation.
Usage
agg_jpeg(
filename = "Rplot%03d.jpeg",
width = 480,
height = 480,
units = "px",
pointsize = 12,
background = "white",
res = 72,
scaling = 1,
snap_rect = TRUE,
quality = 75,
smoothing = FALSE,
method = "slow",
bg
)
Arguments
filename |
The name of the file. Follows the same semantics as the file
naming in |
width , height |
The dimensions of the device |
units |
The unit |
pointsize |
The default pointsize of the device in pt. This will in general not have any effect on grid graphics (including ggplot2) as text size is always set explicitly there. |
background |
The background colour of the device |
res |
The resolution of the device. This setting will govern how device dimensions given in inches, centimeters, or millimeters will be converted to pixels. Further, it will be used to scale text sizes and linewidths |
scaling |
A scaling factor to apply to the rendered line width and text
size. Useful for getting the right dimensions at the resolution that you
need. If e.g. you need to render a plot at 4000x3000 pixels for it to fit
into a layout, but you find that the result appears to small, you can
increase the |
snap_rect |
Should axis-aligned rectangles drawn with only fill snap to the pixel grid. This will prevent anti-aliasing artifacts when two rectangles are touching at their border. |
quality |
An integer between |
smoothing |
A smoothing factor to apply before compression, from |
method |
The compression algorithm to use. Either |
bg |
Same as |
Note
Smoothing is only applied if ragg has been compiled against a jpeg library that supports smoothing.
Examples
file <- tempfile(fileext = '.jpeg')
agg_jpeg(file, quality = 50)
plot(sin, -pi, 2*pi)
dev.off()