Bill Evans | b62414a | 2020-09-14 12:33:38 -0700 | [diff] [blame] | 1 | % Generated by roxygen2: do not edit by hand |
| 2 | % Please edit documentation in R/graphics_helpers.R |
| 3 | \name{graphics_helpers} |
| 4 | \alias{graphics_helpers} |
| 5 | \alias{graphics_dev} |
| 6 | \alias{is_svg} |
| 7 | \alias{dev_chr} |
| 8 | \title{Helper functions to use various graphics devices} |
| 9 | \usage{ |
| 10 | graphics_dev(filename, width, height, res, ..., dev) |
| 11 | |
| 12 | is_svg(dev) |
| 13 | |
| 14 | dev_chr(dev) |
| 15 | } |
| 16 | \arguments{ |
| 17 | \item{filename}{Passed through to the graphics device.} |
| 18 | |
| 19 | \item{width, height}{Plot dimensions in pixels.} |
| 20 | |
| 21 | \item{res}{The resolution of the plot; default is 300.} |
| 22 | |
| 23 | \item{...}{extra parameters passing to the graphics-device function.} |
| 24 | |
| 25 | \item{dev}{Character (e.g., "svg", "pdf") or function (e.g., |
| 26 | \code{grDevices::svg}, \code{grDevices::pdf}).} |
| 27 | } |
| 28 | \value{ |
| 29 | 'graphics_dev': nothing, a plot device is opened |
| 30 | |
| 31 | 'is_svg': logical |
| 32 | |
| 33 | \code{dev_chr}: character |
| 34 | } |
| 35 | \description{ |
| 36 | These helper functions generalize the use of strings (e.g., |
| 37 | \code{"svg"}, \code{"pdf"}) or graphic device functions (e.g., |
| 38 | \code{grDevices::svg}, \code{grDevices::pdf}) for in-table plots. |
| 39 | } |
| 40 | \details{ |
| 41 | \itemize{ |
| 42 | \item \code{graphics_dev} generalizes the use of 'res' and plot dimensions |
| 43 | across graphic devices. Raster-based devices (e.g., 'png', |
| 44 | 'jpeg', 'tiff', 'bmp') tend to use 'res' and the width/height |
| 45 | units default to pixels. All other devices (e.g., 'pdf', 'svg') |
| 46 | tend to use inches as the default units for width/height, and |
| 47 | error when 'res' is provided. |
| 48 | |
| 49 | The current heuristic is the look for the 'res' argument in the |
| 50 | function's formals; if that is present, then it is assumed that |
| 51 | the default units are in pixels, so 'width', 'height', and 'res' |
| 52 | are passed through unmodified. If 'res' is not present, then |
| 53 | 'width' and 'height' are converted from pixels to inches, and |
| 54 | 'res' is not passed to the function |
| 55 | |
| 56 | Another purpose of this function is to generalize the different |
| 57 | graphic functions' use of 'file=' versus 'filename='. |
| 58 | } |
| 59 | |
| 60 | \itemize{ |
| 61 | \item \code{is_svg} determines if the plot device is svg-like, typically one |
| 62 | of \verb{"svg", }grDevices::svg\verb{, or }svglite::svglite` |
| 63 | } |
| 64 | |
| 65 | \itemize{ |
| 66 | \item \code{dev_chr} determines the filename extension for the applicable |
| 67 | plot function; when \code{dev} is a string, then it is returned |
| 68 | unchanged; when \code{dev} is a function, the formals of the function |
| 69 | are checked for clues (i.e., default value of a \verb{file=} argument) |
| 70 | } |
| 71 | } |
| 72 | \section{Functions}{ |
| 73 | \itemize{ |
| 74 | \item \code{graphics_dev}: Generalize 'res' and 'filename across dev functions |
| 75 | |
| 76 | \item \code{is_svg}: Determine if plot device is svg-like |
| 77 | |
| 78 | \item \code{dev_chr}: Determine filename extension |
| 79 | }} |
| 80 | |