
Check Whether the Current Plot Region Is Large Enough
Source:R/isValidPlotRegion.R
isValidPlotRegion.RdTests whether the plot region of the active graphics device meets a
minimal size requirement. This is useful before drawing into small
devices or heavily subdivided layouts (mfrow, layout(),
Shiny render panes), where an undersized region would otherwise fail
with the rather cryptic error "figure margins too large".
Usage
isValidPlotRegion(minPin = .getOption("plot.minPin", c(0.5, 0.5)))Value
a single logical: TRUE if the plot region is at least
minPin inches in both dimensions (or if no device is open),
FALSE otherwise.
Details
The plot region is the area inside the figure margins, as reported by
par("pin"). Its size results from the device dimensions minus
the current margins (mar, oma), so both a small device
and oversized margins can render it degenerate.
If no graphics device is open (dev.cur() == 1), the function
returns TRUE, since the next high-level plot call will open a
fresh device with default dimensions. Note that querying par()
in this state would itself open a device as a side effect, which this
function deliberately avoids.
The function has no side effects and never throws; it is meant as a
guard for conditional plotting, e.g.
if (isValidPlotRegion()) plot(x) else message("device too small").
See also
par() (entries pin, fin, mar),
dev.cur()
Other graphics.layout:
abcCoords(),
axTicks,
axisBreak(),
lineToUser(),
mar(),
plotFacet(),
spreadOut()
