render_ggplot_to_latex: Export a ggplot Figure to LaTeX Format

View source: R/render_ggplot_to_latex.R

render_ggplot_to_latexR Documentation

Export a ggplot Figure to LaTeX Format

Description

This function exports a ggplot figure to a specified path in TikZ format and wraps it in a LaTeX figure environment.

Usage

render_ggplot_to_latex(
  fig = NULL,
  fig_path = NULL,
  sanitize = TRUE,
  width = 6.4,
  height = 3.54,
  fig_out = NULL,
  title = NULL,
  caption = NULL,
  label = NULL,
  copy_fig = TRUE
)

Arguments

fig

A ggplot object to be exported. Must not be NULL.

fig_path

A character string specifying the path where the figure will be saved. Must not be NULL.

sanitize

A logical indicating whether to sanitize the figure. Default is TRUE.

width

A numeric value specifying the width of the figure. Default is 6.4.

height

A numeric value specifying the height of the figure. Default is 3.54.

fig_out

A character string specifying the output path for the wrapped figure. Optional.

title

A character string for the figure title. Optional.

caption

A character string for the figure caption. Optional.

label

A character string for the figure label. Optional.

copy_fig

A logical indicating whether to copy the figure to the clipboard. Default is TRUE.

Value

The original ggplot object, invisibly returned.

Examples

## Not run: 
library(ggplot2)
p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
render_ggplot_to_latex(fig = p, fig_path = "path/to/figure.tex",
               title = "Car Weight vs MPG", caption = "A scatter plot.",
               label = "fig:car_weight")

## End(Not run)

AndreSjuve/texaid documentation built on Oct. 20, 2024, 6:17 a.m.