plotAndSave {ttutils} | R Documentation |
plotAndSave
saves a plot as “pdf” and/or “eps”
and additionally displays the plot.
plotAndSave(plot.func, plot.name, ..., folder = getwd(), format = c("eps", "pdf"), ps.options=list(onefile = TRUE, horizontal = FALSE, paper = "special", width = 7, height = 7), pdf.options = list(onefile = TRUE), do.plot = TRUE, do.return = do.plot)
plot.func |
either a function or a non-empty character string naming the plotting function to be called. |
plot.name |
a character string (without any suffix such as “.pdf” or “.eps”) giving the name of the file where the plot should be saved to. |
... |
additional arguments to be passed to the plotting function. |
folder |
a character string giving the name of the folder to which the plot should be saved. The default is the current directory. |
format |
output format. Must be a subset of (“eps”, “pdf”). The default is to produce both an eps-file and a pdf-file. Can be abbreviated. |
ps.options |
named list of options to be passed to the PostScript
device driver. See postscript for further
details. |
pdf.options |
named list of options to be passed to the PDF
device driver. See pdf for further details. |
do.plot |
logical. If TRUE (the default) the plot is
displayed. |
do.return |
logical. If TRUE the return value of the
plotting function is returned. Defaults to the value of the
parameter do.plot . |
The purpose of this function is to produce a plot on the monitor and to save it to a file simultaneously.
The file name must be given without any file-suffix. Depending on the
argument format
the function then generates either a
PDF-file, an EPS-file or both with the appropriate suffix. The path
should not be included in the file name, since the location where the
files should be saved to is controlled by the parameter folder
.
The function needs a plotting function to be defined, which actually
does the plotting itself. Additional arguments (e.g. further graphical
parameters) can be passed to plotAndSave
, which in turn, passes
these arguments down to the plotting function,
The parameters of the PostScript and the PDF device are controlled by
the arguments ps.options
and pdf.options
, respectively.
the return value of the plotting function.
When using Trellis plots from package lattice one has to assure
that the plotting function actually does the plotting. Since
the default behaviour of Trellis plots is just to return the Trellis
object, one should wrap the call to the particular lattice
function in a call of the function print
. The generic function
print
ensures that the plot is displayed and not just returned
as an object.
Thorn Thaler
## Not run: ## Plotting Function # For 'lattice' graphics: # WRONG: # f <- function(x, ...) xyplot(x~sin(x), ...) # CORRECT: # f <- function(x, ...) print(xyplot(x~sin(x), ...)) f <- function(x, ...) plot(x, sin(x), col=2, type="l", ...) # Save the plot as "Sine_Function.pdf" in the current folder # and add a title to the plot plotAndSave(f, "Sine_Function", x=seq(-pi, pi, length=100), main="Sine-Function", format="p") ## End(Not run)