save_plot() wraps ggplot2::ggsave() and offer option to remove white spaces around figures (creates a additional file in output/figures/trim; uses trim_fig)

save_plot(
  object,
  filename = NULL,
  dir_to_save = NULL,
  width = NA,
  height = NA,
  format = NULL,
  units = NULL,
  dpi = NULL,
  overwrite = FALSE,
  trim = FALSE
)

Arguments

object

a ggplot object

filename

a character vector with the name of the file to save. Default is NULL and saves with the name of the object

dir_to_save

a character vector with the name of the directory to save

width

a numerical vector with the width of the figure

height

a numerical vector with the height of the figure

format

a character vector with format of the figure. Can "jpeg", "tiff", "png" (default), or "pdf"

units

a character vector with the units of the figure size. Can be "in", "cm" (default), or "mm"

dpi

a numerical vector with the resolution of the figure. Default is 300

overwrite

logical

trim

logical

Acknowledgment

save_plot() is derived from write_plot(), available in the excellent start project template

Examples

if (FALSE) {
library(misc)
ipak(c("ggplot2", "dplyr"))
create_dirs()
p <- mtcars %>%
  ggplot() +
  aes(x = mpg, y = cyl) +
  geom_point()
save_plot(p)
}