Skip to contents

Save a plot or map then update the EXIF metadata for the title, author, and create data. ggsave_ext() also supports creating a file name based on a sentence case name with spaces (e.g. "Baltimore city map") and appending a label (e.g. "baltcity") as a prefix to the output file name.

Usage

ggsave_ext(
  plot = ggplot2::last_plot(),
  name = NULL,
  label = NULL,
  prefix = NULL,
  postfix = NULL,
  filename = NULL,
  device = NULL,
  filetype = NULL,
  path = NULL,
  paper = NULL,
  orientation = "portrait",
  width = NULL,
  height = NULL,
  units = "in",
  scale = 1,
  dpi = 300,
  bgcolor = NULL,
  exif = FALSE,
  title = NULL,
  author = NULL,
  keywords = NULL,
  args = NULL,
  ...
)

ggsave_social(
  plot = ggplot2::last_plot(),
  image = "Instagram post",
  platform = NULL,
  format = NULL,
  orientation = NULL,
  name = NULL,
  filename = NULL,
  filetype = "jpeg",
  dpi = 72,
  width = 1080,
  height = 1080,
  units = "px",
  ...
)

gtsave_ext(
  gt_object,
  name = NULL,
  label = NULL,
  prefix = NULL,
  postfix = NULL,
  filename = NULL,
  filetype = NULL,
  path = NULL,
  ...
)

Arguments

plot

Plot to save, defaults to last plot displayed.

name

Plot name, used to create filename (if filename is NULL) using make_filename()

label

Label to combine with name converted to snake case with janitor::make_clean_names(). The label is designed to identify the area or other shared characteristics across multiple data files, maps, or plots.

prefix

File name prefix. "date" adds a date prefix, "time" adds a date/time prefix; defaults to NULL.

postfix

File name postfix; defaults to NULL.

filename

File name to create on disk.

device

Device to use. Can either be a device function (e.g. png), or one of "eps", "ps", "tex" (pictex), "pdf", "jpeg", "tiff", "png", "bmp", "svg" or "wmf" (windows only).

filetype

File type or extension.

path

Path of the directory to save plot to: path and filename are combined to create the fully qualified file name. Defaults to the working directory.

paper

Paper matching name from paper_sizes (e.g. "letter"). Not case sensitive.

orientation

Page orientation ("portrait", "landscape", or "square").

width, height, units

Plot size in units ("in", "cm", "mm", or "px"). If not supplied, uses the size of current graphics device.

scale

Multiplicative scaling factor.

dpi

Plot resolution. Also accepts a string input: "retina" (320), "print" (300), or "screen" (72). Applies only to raster output types.

bgcolor

Background color to optionally override plot.background theme element.

exif

If TRUE, the EXIF metadata for the exported file is updated with the exifr package; defaults to FALSE.

title

Title to add to file metadata with exiftoolr, Default: NULL.

author

Author to add to file metadata with exiftoolr, Default: NULL.

keywords

Keyword(s) added to file metadata with with exiftoolr, Default: NULL.

args

Alternate arguments passed to exiftoolr::exif_call(). If args is not NULL, title, author, date, and keywords are ignored; defaults to NULL.

...

Additional parameters passed to ggplot2::ggsave() or gt::gtsave().

image

Image size name, Default: NULL

platform

Social media platform, "Instagram", "Facebook", or "Twitter", Default: NULL

format

Image format, "post", "story", or "cover", Default: NULL

gt_object

A gt table to save to file.

gtsave_ext

The gtsave_ext wraps the equivalent function gt::gtsave() with a similar structure for creating custom file names. This function does not currently support EXIF metadata updates although this option may be added in the future.

Examples

if (FALSE) {
  ggplot2::ggplot() +
    layer_location_data(
      data = system.file("shape/nc.shp", package = "sf")
    )

  ggsave_ext(
    name = "counties",
    label = "North Carolina",
    device = "pdf",
    paper = "letter"
    )
}