plot_save: Plot export in multiple formats

View source: R/plot_save.R

plot_saveR Documentation

Plot export in multiple formats

Description

Exports plots based on ggplot2 in vector (PDF, SVG), raster (PNG) and R data format (Rds).

Usage

plot_save(plot, filepath, height, width, unit = "in", dpi = 600)

Arguments

plot

Plot to be exported. Needs to be based on ggplot2 (datavis-created plots comply with this).

filepath

Character. The filepath for the exported plot, relative to the working directory. Do not add file extension, appropriate extension will be added to each exported file.

height

Numeric. The height of the exported plot in the desired length unit.

width

Numeric. The width of the exported plot in the desired length unit.

unit

Character. The unit to be used as height and width. "in" for inches, "cm" for centimeters and "mm" for millimeters. Defaults to "in".

dpi

Integer. The resolution of the exported PNG image in dots per inch. Defaults to 600.

Details

PNG and PDF files are exported using the ggplot2-based ggsave function. Exported PNG images are anti-aliased using the Cairo graphics library. Exported SVG graphics are drawn using the R-native SVG graphics device. This is because SVG graphics exported by ggsave are not rendered properly by the graphic design software Affinity Designer. The downside of exporting SVG with the native graphics device is that the text is drawn as paths instead of text, so it cannot be easily modified as text in graphic design software (e.g. set as bold, italics, etc).

Value

Exports plot without returning a value.


dimitriskokoretsis/datavis documentation built on Oct. 14, 2022, 3:35 p.m.