| graphics_helpers {kableExtra} | R Documentation |
Helper functions to use various graphics devices
Description
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.
Usage
graphics_dev(filename, width, height, res, ..., dev)
is_svg(dev)
dev_chr(dev)
Arguments
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.,
|
Details
-
graphics_devgeneralizes 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_svgdetermines if the plot device is svg-like, typically one of"svg", grDevices::svg, or svglite::svglite'
-
dev_chrdetermines the filename extension for the applicable plot function; whendevis a string, then it is returned unchanged; whendevis a function, the formals of the function are checked for clues (i.e., default value of afile=argument)
Value
graphics_dev: nothing, a plot device is opened
'is_svg': logical
dev_chr: character
Functions
-
graphics_dev(): Generalizeresandfilenameacross device functions -
is_svg(): Determine if plot device is svg-like -
dev_chr(): Determine filename extension