Introduce plot to file function

sma_plot_file(fname, ftype, title_list, legend_list, fun, ...)
can be used to write plot to a file.
It supports all output filetypes R can handle. Title and legend
arguments can be passed as lists.
All available plotting functions can be used, arguments go into a
variable argument list.
This commit is contained in:
Jens Sauer 2020-10-22 18:23:29 +02:00
parent fffd300955
commit a8c4b327a0

28
utils.R Normal file
View File

@ -0,0 +1,28 @@
# secMalASCT utilities
#
# License: GPL version 3
# Jens Mathis Sauer (c) 2020
#
# Write plot to filename
#
# This will plot "fun" with arguments "..." as filetype "ftype" and
# the output to "filename". Title and legends can be passed as list,
# or NULL if not needed.
# Default filesize is 3000x3000 px and 300 dpi resolution.
#
sma_plot_file <- function(fname, ftype, title_list, legend_list, fun, ...) {
# Open file for writing
ftype(filename = fname, width = 3000, height = 3000, res = 300)
# run "fun" with passed arguments
do.call(fun, list(...))
if (!is.null(title_list)) {
do.call(title, title_list)
}
if(!is.null(legend_list)) {
do.call(legend, legend_list)
}
dev.off()
}