The code you need to look at to understand the differences is in a non-exported function named plot_dev
in the ggplot namespace. You get this information by looking at the ggsave code. The line that dispatches to a device is:
dev <- plot_dev(device, filename, dpi = dpi)
# Look at that function
getAnywhere(plot_dev) # not exported, so need getAnywhere
The logic of plot_dev
is to first check to see whether the "device" value was given as a function name and if so to just call that function. That is what happens in the first two calls you offered. If it's not a function and no character value for "device" is given (which is the situation in your third call), then plot_dev dispatchs from a named list of functions based on the extension of the file name offered as "filename". The type argument gets passed to the png
function to get the 'cairo' version of png
used rather than the default.
This is the list of possible devices and their default arguments. Those defaults can be offered alternate values and the "dots" can be used to specify other device parameters. (See their respective help pages for specifics):
devices <- list(eps = eps,
ps = eps,
tex = function(filename, ...)
grDevices::pictex(file = filename, ...),
pdf = function(filename, ..., version = "1.4")
grDevices::pdf(file = filename, ..., version = version),
svg = function(filename, ...) vglite::svglite(file = filename, ...),
emf = function(...) grDevices::win.metafile(...),
wmf = function(...) grDevices::win.metafile(...),
png = function(...) grDevices::png(..., res = dpi,
units = "in"),
jpg = function(...) grDevices::jpeg(..., res = dpi,
units = "in"),
jpeg = function(...) grDevices::jpeg(..., res = dpi,
units = "in"),
bmp = function(...) grDevices::bmp(..., res = dpi,
units = "in"),
tiff = function(...) grDevices::tiff(..., res = dpi,
units = "in"))
Notice that the first two parameters are given values of eps
. That is an internally defined function:
eps <- function(filename, ...) {
grDevices::postscript(file = filename, ..., onefile = FALSE,
horizontal = FALSE, paper = "special")
device = "eps"
? – Knighterrantry