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.
map_ggsave_ext()
can take a list of {ggplot2} plots (e.g. a list of plot
generated by purrr::map()
) and create multiple files using the same
parameters or use the {gridExtras} package to create a single combined PDF
file.
Usage
ggsave_ext(
plot = ggplot2::last_plot(),
name = NULL,
label = NULL,
prefix = NULL,
postfix = NULL,
increment = NULL,
filename = NULL,
device = NULL,
fileext = NULL,
filetype = NULL,
path = NULL,
paper = NULL,
orientation = NULL,
width = NULL,
height = NULL,
asp = NULL,
units = getOption("papersize.ggsave_units", "in"),
scale = 1,
dpi = 300,
bgcolor = NULL,
exif = FALSE,
title = NULL,
author = NULL,
keywords = NULL,
args = NULL,
overwrite = TRUE,
ask = FALSE,
preview = FALSE,
limitsize = TRUE,
quiet = FALSE,
...
)
ggsave_social(
plot = ggplot2::last_plot(),
image = "Instagram post",
platform = NULL,
format = NULL,
orientation = NULL,
name = NULL,
filename = NULL,
fileext = "jpeg",
filetype = NULL,
dpi = 72,
width = 1080,
height = 1080,
units = "px",
...
)
map_ggsave_ext(
plot,
name = NULL,
label = NULL,
prefix = NULL,
postfix = "pg_",
filename = NULL,
device = NULL,
fileext = NULL,
filetype = NULL,
path = NULL,
overwrite = TRUE,
...,
single_file = TRUE,
onefile = TRUE
)
Arguments
- plot
Plot to save, defaults to last plot displayed. If plot is an "magick-image" class object, it is converted to a plot using
magick::image_ggplot()
- name
Plot name, used to create filename (if filename is
NULL
) usingfilenamr::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. label is ignored if name is NULL or if name includes a file extension.- 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
.- increment
If
TRUE
, increment digits in string by 1. If numeric, increment digits in string by value. IfNULL
, 0, or if no digits are present in string, return string as is.- 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). If
NULL
(default), the device is guessed based on thefilename
extension.- fileext
File type or extension. Optional if filename or path include a file extension.
- filetype
File type (used if fileext is
NULL
).- path
Path of the directory to save plot to:
path
andfilename
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
Plot size in units expressed by the
units
argument. If not supplied, uses the size of the current graphics device.- asp
Numeric aspect ratio used to determine width or height if only one of the two arguments is provided; defaults to
NULL
.- units
One of the following units in which the
width
andheight
arguments are expressed:"in"
,"cm"
,"mm"
or"px"
.- 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 toFALSE
.- title
Title to add to file metadata with exiftoolr, Default:
NULL
.Author to add to file metadata to the "Author" and "XMP-dc:creator" tags. Default:
NULL
.- keywords
Keyword(s) added to file metadata to "IPTC:Keywords" and "XMP-dc:Subject" tags. Defaults to
NULL
.- args
Alternate arguments passed to
exiftoolr::exif_call()
. Other tag parameters are appended to args if they are notNULL
.- overwrite
If
TRUE
(default), overwrite any existing file with the same name or ask to overwrite ifask = TRUE
. Passed tofilenamr::check_file_overwrite()
.- ask
If
TRUE
, ask before overwriting file with the same name. Defaults toFALSE
. Passed tofilenamr::check_file_overwrite()
.- preview
If
TRUE
, open saved file in default system application. Based on ggpreview from tjmisc package.- limitsize
When
TRUE
(the default),ggsave()
will not save images larger than 50x50 inches, to prevent the common error of specifying dimensions in pixels.- quiet
If
TRUE
(default), suppress function messages.- ...
Arguments passed on to
ggplot2::ggsave
create.dir
Whether to create new directories if a non-existing directory is specified in the
filename
orpath
(TRUE
) or return an error (FALSE
, default). IfFALSE
and run in an interactive session, a prompt will appear asking to create a new directory when necessary.
- image
Image name passed to name parameter of
get_social_size()
.- platform
Social media platform, "Instagram", "Facebook", or "Twitter", Default:
NULL
- format
Image format, "post", "story", or "cover", Default:
NULL
- single_file, onefile
If
TRUE
, usegridExtra::arrangeGrob()
to create an arrangelist class object thatggplot2::ggsave()
can save as a single multi-page file. Note: this does not work with plots modified with patchwork including inset maps created with themaplayer::layer_inset()
function.