This function is a wrapper around ggsave
from the
ggplot2
package that allows you to write a ggplot object as part of
a knitr document as an output for later use. It is designed to be used
in a code block. The file name, if not specified, will be the label of
the code block.
Arguments
- gg_obj
The ggplot to be written. If not specified, the last ggplot created will be written.
- file
The name of the file to be written. If not specified, the label of the code block will be used.
- target_dir
The directory where the file will be written. If not specified, the current working directory will be used.
- device
The device to be used for saving the ggplot. Options include "pdf" (default), "png", "jpeg", "tiff", and "svg".
- theme
The ggplot2 theme to be applied to the ggplot. Default is the theme specified in the ggplot2 options.
- ...
Additional arguments to be passed to the
ggsave
function from theggplot2
package.