graphics_helpers | R Documentation |
These helper functions generalize the use of strings (e.g.,
"svg"
, "pdf"
) or graphic device functions (e.g.,
grDevices::svg
, grDevices::pdf
) for in-table plots.
graphics_dev(filename, width, height, res, ..., dev)
is_svg(dev)
dev_chr(dev)
filename |
Passed through to the graphics device. |
width , height |
Plot dimensions in pixels. |
res |
The resolution of the plot; default is 300. |
... |
extra parameters passing to the graphics-device function. |
dev |
Character (e.g., "svg", "pdf") or function (e.g.,
|
graphics_dev
generalizes the use of 'res' and plot dimensions
across graphic devices. Raster-based devices (e.g., 'png',
'jpeg', 'tiff', 'bmp') tend to use 'res' and the width/height
units default to pixels. All other devices (e.g., 'pdf', 'svg')
tend to use inches as the default units for width/height, and
error when 'res' is provided.
The current heuristic is the look for the 'res' argument in the function's formals; if that is present, then it is assumed that the default units are in pixels, so 'width', 'height', and 'res' are passed through unmodified. If 'res' is not present, then 'width' and 'height' are converted from pixels to inches, and 'res' is not passed to the function
Another purpose of this function is to generalize the different graphic functions' use of 'file=' versus 'filename='.
is_svg
determines if the plot device is svg-like, typically one
of "svg",
grDevices::svg, or
svglite::svglite'
dev_chr
determines the filename extension for the applicable
plot function; when dev
is a string, then it is returned
unchanged; when dev
is a function, the formals of the function
are checked for clues (i.e., default value of a file=
argument)
graphics_dev
: nothing, a plot device is opened
'is_svg': logical
dev_chr
: character
graphics_dev()
: Generalize res
and filename
across device functions
is_svg()
: Determine if plot device is svg-like
dev_chr()
: Determine filename extension
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.