Saves a ggplot object to disk at a set physical size. Allows specific maximum dimensions with an optional target aspect ratio to fit into specific configurations for publication. e.g. a half page plot or a third of a 2 column page. Allows output in pdf for journal publication or png for inclusion in documents, and makes sure that the outputs are near identical.
Arguments
- ...
Named arguments passed on to
.gg_save_asfilenamebase of target filename (excluding extension).
plota ggplot
sizea standard size see
std_sizemaxWidthmaximum width in inches
maxHeightmaximum height in inches
aspectRatiodefaults to maxWidth/maxHeight
formatssome of svg, png, pdf, Rdata, eps, ...
...Named arguments passed on to
svglite::svglitepointsizeDefault point size.
standaloneProduce a standalone svg file? If
FALSE, omits xml header and default namespace.idA character vector of ids to assign to the generated SVG's. If creating more SVG files than supplied ids the exceeding SVG's will not have an id tag and a warning will be thrown.
fix_text_sizeShould the width of strings be fixed so that it doesn't change between svg renderers depending on their font rendering? Defaults to
TRUE. IfTRUEeach string will have thetextLengthCSS property set to the width calculated by systemfonts andlengthAdjust='spacingAndGlyphs'. Setting this toFALSEcan be beneficial for heavy post-processing that may change content or style of strings, but may lead to inconsistencies between strings and graphic elements that depend on the dimensions of the string (e.g. label borders and background).scalingA scaling factor to apply to the rendered line width and text size. Useful for getting the right sizing at the dimension that you need.
always_validShould the svgfile be a valid svg file while it is being written to? Setting this to
TRUEwill incur a considerable performance hit (>50% additional rendering time) so this should only be set toTRUEif the file is being parsed while it is still being written to.fileIdentical to
filename. Provided for backward compatibility.
Value
the output is an sensible default object that can be displayed given the context it is called in, for example if knitting an RMarkdown document a link to the png file for embedding, if latex a link to the pdf file.
Details
For maximum cross platform reproducibility we are using the combination of
systemfonts for font management, svglite to render the canonical output
rsvg to convert that to pdf, and ragg for bitmap formats.
In some situations rsvg fails in which case we fall back to rendering in a
headless chrome instance. This rather complicated pipeline ensures modern
webfont support, and editable SVG or PDF.