fd_add {ggfigdone}R Documentation

Add a ggplot object to the ggfigdone database

Description

This function adds a ggplot object to the ggfigdone database. It can also be utilized to update an existing figure using its figure ID.

Usage

fd_add(
  name,
  g = last_plot(),
  fdObj = fd_get_db(),
  width = 10,
  height = 10,
  units = "cm",
  dpi = 200,
  overwrite = FALSE,
  id = uuid::UUIDgenerate()
)

Arguments

name

A character string representing the figure name.

g

A ggplot object.

fdObj

An object of class fdObj.

width

A numeric value specifying the width of the canvas.

height

A numeric value specifying the height of the canvas.

units

A character string indicating the units of the canvas.

dpi

A numeric value denoting the dpi of the canvas.

overwrite

A logical value. If set to TRUE, the function will overwrite the figure if it already exists. If set to FALSE, the function will terminate with an error message.

id

A character string representing the figure ID. If not provided, the function will generate a random ID. Alternatively, an existing ID can be provided to update the corresponding figure.

Value

An object of class fdObj.

Examples

library(ggplot2)

## Initial ggfigdone database using `fd_init`
db_dir = file.path(tempdir(), "fd_add_exp")
fo = fd_init(db_dir, rm_exist = TRUE)

## Draw a ggplot figure
g = ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point()

## Add the figure to the database
fd_add(g = g, name  = "fig1", fo)

## Add the same figure with a different name
fd_add(g = g, name  = "fig2", fo)

## Show the updated ggfigdone database
print(fo)


[Package ggfigdone version 0.1.2 Index]