Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

graphics_helpers

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., grDevices::svg, grDevices::pdf).

Details

  • 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)

Value

'graphics_dev': nothing, a plot device is opened

'is_svg': logical

dev_chr: character

Functions

  • graphics_dev: Generalize 'res' and 'filename across dev functions

  • is_svg: Determine if plot device is svg-like

  • dev_chr: Determine filename extension


kableExtra

Construct Complex Table with 'kable' and Pipe Syntax

v1.3.4
MIT + file LICENSE
Authors
Hao Zhu [aut, cre] (<https://orcid.org/0000-0002-3386-6076>), Thomas Travison [ctb], Timothy Tsai [ctb], Will Beasley [ctb], Yihui Xie [ctb], GuangChuang Yu [ctb], Stéphane Laurent [ctb], Rob Shepherd [ctb], Yoni Sidi [ctb], Brian Salzer [ctb], George Gui [ctb], Yeliang Fan [ctb], Duncan Murdoch [ctb], Bill Evans [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.