[R] Properly initializing a plot

Frank E Harrell Jr fharrell at virginia.edu
Tue Sep 3 18:30:01 CEST 2002


I have many functions for high-level plotting that early on in their code do something like strwidth('string', units='inches') before plotting.  I do this before plot() to set the correct margins with par(mai=...), to leave room for wide text on the left or right margins.

If the plotting device is not opened strwidth( ) causes an error that plot.new() needs to be called.  I can sense the need for plot.new() in the code using if(length(dev.list()).  If using postscript( ) as the device instead of the screen (X11()) I need to issue plot.new even though dev.list() is non-null.  If I routinely call plot.new() I will get extra empty panels if the code in the calling environment included par(mfrow=c(#rows,#columns)).

Does anyone know of almost foolproof code for initializing a new plot inside a high-level plotting function but not unnecessarily doing so?  Thanks in advance.
-- 
Frank E Harrell Jr              Prof. of Biostatistics & Statistics
Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
U. Virginia School of Medicine  http://hesweb1.med.virginia.edu/biostat
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list