gfig_saver: Saves ggplot and documentation

View source: R/gfig_saver.R

gfig_saverR Documentation

Saves ggplot and documentation

Description

Simplify plotting for larger projects by simultaneously saving the plot, documentation of the plot, and the ggplot object itself as an RDS file.

Usage

gfig_saver(
  filename,
  description,
  gfig = last_plot(),
  from.description = NULL,
  is.knitted = FALSE,
  width = 12,
  height = 8,
  res = 300,
  units = "in",
  ...
)

Arguments

filename

Name of the file (can include filepath) WITHOUT FILETYPE. Function will automatically save pdf and jpg filetypes.

description

Description of the figure generated to save as metadata. It is useful to treat this as a prototype figure caption, but with any additional details on methods, specific parameters, etc.

gfig

Figure, defaults to the last plot displayed.

from.description

Optional additional description of where the figures were generated - the scripts and project.

is.knitted

If this function is being used in a knitted document, the knitr package can automatically save the script name in the description. Default is FALSE.

width

Width of the saved figure; default is 12 inches.

height

Height of the saved figure; default is 8 inches.

res

Resolution of the saved figure; default is 300 dpi.

units

Units for height and with; default is inches. Options include "cm", "mm", and "px"

...

additional ggplot2 arguments

Value

none

Examples

library(ggplot2)
x= 1:10
y = x + rnorm(10)
dat = data.frame(x, y)
gp = ggplot(data = dat, aes(x=x, y=y))+
  geom_point()
gfig_saver(filename="testfig",
           description=c("This is an example figure of X = Y + noise",
                         "note that this is just for demonstration"),
           gfig = gp)

cbedwards/cedwards documentation built on Feb. 24, 2023, 6:53 p.m.