Display And Save A Plot
plotAndSave saves a plot as “pdf”, “(e)ps”,
“jp(e)g”, “png”, “bmp”, “tiff”,
“emf” and/or “wmf” and additionally displays
1 2 3 4 5 6 7 8 9 10
plotAndSave(plot.func, plot.name, ..., folder=getwd(), format=c("eps", "pdf"), options=list(eps = list(onefile=TRUE, horizontal=FALSE, paper="special", width=7, height=7), ps = list(onefile=TRUE, horizontal=FALSE, paper="special", width=7, height=7), pdf = list(onefile=TRUE)), do.plot=TRUE, do.return=do.plot)
either a function or a non-empty character string naming the plotting function to be called.
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.
a character string giving the name of the folder to which the plot should be saved. The default is the current directory.
output format. Must be a subset of (“pdf”, “(e)ps”, “jp(e)g”, “png”, “bmp”, “tiff”, “emf”, “wmf”). The latter two can be used only on with a Windows OS. The default is to produce both an eps-file and a pdf-file. Can be abbreviated.
named list of options to be passed to the respective device driver. Each entry of the list is an option list for the device corresponding to the name of the list item.
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
format the function then generates the respective file
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
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 devices are controlled by the arguments
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
## 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="pd") ## End(Not run)
Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.