ggsave
Exports plot to a file. Supported formats: SVG, HTML, PNG, JPEG and TIFF. Note: in some configurations raster formats might not be supported.
If path
is not specified, the output file will be saved in ${user.dir}/lets-plot-images
.
Notes
The output format is inferred from the file extension.
For PNG and PDF:
If
w
,h
,unit
, anddpi
are all specified:The plot's pixel size (default or set via ggsize()) is ignored.
The output size is computed from the given dimensions and DPI.
The plot is resized to fit the specified
w
xh
area, which may affect the layout.If only
dpi
is specified:The plot's pixel size (default or set via ggsize()) is converted to inches assuming the standard display PPI of 96 PPI.
The output size is computed from this size and
dpi
.The plot maintains its aspect ratio, preserving layout, tick labels, and other visual elements.
Useful for printing - the plot will appear nearly the same size as on screen.
If
w
andh
are not specified:The
scale
parameter is used to determine the output size.The plot maintains its aspect ratio, preserving layout, tick labels, and other visual elements.
Useful for generating high-resolution images suitable for publication.
For SVG:
If
w
,h
, andunit
are specified:The plot's pixel size (default or set via ggsize()) is ignored.
The output size is set from the given values.
For HTML:
If
w
andh
are specified:The plot's pixel size (default or set via ggsize()) is ignored.
The output size is determined directly from the specified
w
andh
, which are treated as pixel values.
Examples
Return
Absolute pathname of the created file.
Parameters
Plot to export.
Name of the file. Must include an extension matching one of the supported formats: .svg
, .html
/.htm
, .png
, .jpeg
/.jpg
, or .tiff
/.tif
Scaling factor (only for raster formats). Default: 2.0
Width of the output image in units.
Height of the output image in units.
Unit of the output image. One of: "in"
, "cm"
, "mm"
, "px"
. Only applicable when exporting to SVG, PNG, JPG, or TIFF. For HTML, the unit is always "px"
(pixels). Default: "px" (pixels) for SVG, "in" (inches) for the raster formats (PNG, JPG, and TIFF).
Resolution in dots per inch. Only applicable when exporting to the raster formats: PNG, JPG, or TIFF. The default value depends on the unit
:
for
"px"
it is96
(output image will have the same pixel size asw
andh
values)for physical units (
"in"
,"cm"
,"mm"
) it is300
.
Path to a directory to save image files in. Default: ${user.dir}/lets-plot-images