zipfR.plotutils {zipfR} | R Documentation |
Conveniently create plots with different layout and in different output formats (both on-screen and various graphics file formats).
Each plot is wrapped in a pair of zipfR.begin.plot
and
zipfR.end.plot
commands, which make sure that a suitable
plotting window / image file is opened and closed as required. Format
and dimensions of the plots are controlled by global settings made
with zipfR.par
, but can be overridden in the
zipfR.begin.plot
call.
zipfR.pick.device
automatically selects a default device by
scanning the specified vector for strings of the form --pdf
,
--eps
, etc.
NB: These are advanced functions to fine-tune plotting
output. For basic plotting functionalities (that should be
sufficient in most cases) see plot.spc
and
plot.vgc
instead.
zipfR.pick.device(args=commandArgs()) zipfR.begin.plot(device=zipfR.par("device"), filename="", width=zipfR.par("width"), height=zipfR.par("height"), bg=zipfR.par("bg"), pointsize=zipfR.par("pointsize")) ## plotting commands go here zipfR.end.plot()
args |
a character vector, which will be scanned for strings of
the form --pdf , --eps , etc. If args is not
specified, the command-line arguments supplied to R will be
examined. |
device |
name of plotting device to be used (see "Devices" below) |
filename |
for graphics file devices, basename of the
output file. A suitable extension for the selected file format will
be added automatically to filename . This parameter is
ignored for screen devices. |
width, height |
width and height of the plotting window or image, in inches |
bg |
background colour of the plotting window or image (use
"transparent" for images with transparent background) |
pointsize |
default point size for text in the plot |
zipfR.begin.plot
opens a new plotting window or image file of
the specified dimensions (width
, height
), using the
selected graphics device (device
). Background colour
(bg
) and default point size (pointsize
) are set as
requested. Then, any global graphics parameter settings (defined with
the init.par
option of zipfR.par
) are applied.
See the zipfR.par
manpage for the "factory default"
settings of these options.
zipfR.end.plot
finalizes the current plot. For image file
devices, the device will be closed, writing the generated file to
disk. For screen devices, the plotting window remains visible until a
new plot is started (which will close and re-open the plotting
window).
The main purpose of the zipfR
plotting utilities is to make it
easier to draw plots that are both shown on screen (for interactive
work) and saved to image files in various formats. If an R script
specifies filename
s in all zipfR.begin.plot
commands, a
single global parameter setting at the start of the script is
sufficient to switch from screen graphics to EPS files, or any other
supported file format.
The factory-default graphics device is x11
, which is available
on all major platforms (sometimes as an alias for a native device).
On Mac OS X, the Aqua GUI version of R defaults to the quartz
device, which produces higher-quality images.
The png
bitmap device may not be available on all platforms,
and may also require access to an X server. Since the width and
height of a PNG device have to be specified in pixels rather than
inches, zipfR.begin.plot
translates the width
and
height
settings, assuming a resolution of 150 dpi. Use of
the png
device is strongly discouraged. A better way of
producing high-quality bitmaps is to generate EPS image (with the
eps
device) and convert them to PNG or JPEG format with the
external pstoimg
program (part of the latex2html
distribution).
zipfR.pick.device
will issue a warning if multiple flags
matching supported graphics devices are found. However, it is not an
error to find no matching flag, and all unrecognized strings are
silently ignored.
Currently, the following devices are supported (and can be used in the
device
argument).
Screen devices:
x11
quartz
Graphics file devices:
eps
postscript
device with appropriate settings)
pdf
png
x11
, quartz
, postscript
,
pdf
and png
for more information about the
supported graphics devices
zipfR
-specific plotting commands are plot.spc
and
plot.vgc
## these graphics parameters will be set for every new plot ## Not run: zipfR.par(init.par=list(bg="lightblue", cex=1.3)) ## Not run: zipfR.par(width=12, height=9) ## will be shown on screen or saved to specified file, depending on ## selected device (eps -> "myplot.eps", pdf -> "myplot.pdf", etc.) ## Not run: zipfR.begin.plot(filename="myplot") ## Not run: plot.spc(Brown100k.spc) ## Not run: zipfR.end.plot() ## By starting an R script "myplots.R" with this command, you can ## display plots on screen when stepping through the script in an ## interactive session, or save them to disk files in various ## graphics formats with "R --no-save --args --pdf < myplots.R" etc. ## Not run: zipfR.pick.device()