Split a Graphics Display and Control Multiple Screens

DESCRIPTION:
Split a graphics display into multiple screens, change the current screen, close one or all the screens, erase them, or construct a matrix representation of screen positions.

USAGE:
split.screen(figs, screen=<<see below>>, erase=T)
screen(n=<<see below>>, new = T)
erase.screen(n=<<see below>>, eject = F)
close.screen(n, all = F)
prompt.screen(delta = 1/8, draw = T)

REQUIRED ARGUMENTS:
figs:
a vector of the form c(n,m) where n and m are integers indicating a matricial arrangement of screens in the display; or an N by 4 matrix where N is the number of screens and each row specifies the position of a screen on the display in terms of relative coordinates in a plane represented by c(0,1,0,1). For each row the first 2 numbers represent the x-coordinates of the screen (first the left corner and second the right corner) and the next are the two y-coordinates (first the bottom, and second the top). Use prompt.screen to create this matrix interactively.
n:
a number representing the screen to be activated by screen, or erased by erase.screen, or closed by close.screen in which case it could also be a vector (the active screen cannot be closed). The default value for screen and erase.screen is the currently active screen.

OPTIONAL ARGUMENTS:
screen:
number of the screen to split. By default it carves up the currently active screen, which initially is the entire display (denoted as screen 0).
erase:
logical flag: should the display or screen being carved up be cleared?
new:
logical flag: should screen be cleared?
eject:
logical flag: should the current page be ejected? On non-interactive devices like PostScript printers, this will advance to a new page. On exit, the first valid screen is left active.
all:
logical flag: should all screens be closed? Set all = TRUE to exit the split-screen mode.
delta:
spacing, in inches, used to snap or line up adjacent screens; if corners of a newly created screen are less than delta inches from a neighboring screen, screen borders are made to coincide.
draw:
logical flag: should the display be cleared and screen borders drawn?

VALUE:
split.screen returns the indices of the newly created screens. With no arguments, split.screen returns a list of current valid screens or FALSE if not running under the split-screens environment.

close.screen returns the index numbers of the active screens left.

screen, erase.screen, and close.screen return FALSE if invoked outside the split-screen environment.

prompt.screen returns an N by 4 matrix of screen coordinates where N is determined by the desired number of screens entered interactively and the coordinates are determined by a point-and-click interaction using locator. This matrix can then be given to split.screen to set up a multiple screen environment.


SIDE EFFECTS:
split.screen initializes the objects .Scr.info, .Active.screen, .Init.gs, and .GS.pars in the session database to store the graphics states for all screens.

erase.screen causes the first valid screen to be made active (in most cases this is screen 1) on exit.

close.screen closes (i.e., disables) the specified screens. Graphics output present at closing is left intact.


DETAILS:
These functions provide a means to divide up the graphics display into multiple screens or figures of various sizes. The split-screen mode is an alternative to the usual multiple-figure mode obtained by par(mfrow=c(n,m)), and it is useful for interacting with individual figures and for producing non-matricial arrangements of plots; however, the two modes are not compatible i.e., you cannot mix calls to split.screen and par(mfrow)=c(n,m)).

Graphics input and output is directed to and from different screens by calling screen to designate the active one. If you move to a new screen and new is FALSE, then a call to a high-level plot function will not clear it; the plot will be superimposed on anything already on the screen. If, however, you call high-level plot functions twice in an active screen, the second call starts a new page, and all the other screens on that page will be empty.

As part of the initialization, split.screen activates the first screen in figs.

Screens can be recursively divided. See the examples.

Use close.screen(all=T) to "unsplit" the display.

Outer margins are not defined in the context of split-screens, thus the graphics parameters oma and omi should not be used.

If any screen in figs is smaller than half of the horizontal or vertical dimensions of the graphics display, the character expansion factor parameter cex is set to 0.5 in all the screens.


WARNINGS:
These functions are not compatible with some other plotting functions in S-PLUS like pairs, acf.plot, and coplot, given the way they re-define the graphics display parameters.

They cannot be used with multiple devices either.


SEE ALSO:
par , locator .

EXAMPLES:
#Example 1
split.screen(c(2,1))             # split display into two screens
[1] 1 2
split.screen(c(1,3), screen = 2) # now split the bottom half into 3
[1] 3 4 5
screen(1) # prepare screen 1 for output
tsplot(lynx)
screen(4) # prepare screen 4 for output
tsplot(lag(lynx))
dev.print()
close.screen(all = T) # exit split-screen mode

#Example 2 split.screen(c(2,1)) # split display into two screens [1] 1 2 split.screen(c(1,2),2) # split bottom half in two [1] 3 4 tsplot(corn.rain) # screen 3 is active, draw plot erase.screen() #forgot label, erase and redraw tsplot(corn.rain, ylab= "rain in inches") screen(1) # prepare screen 1 for output tsplot(corn.rain) legend(1902, 9, c("corn", "yield"), lty=1:2) screen(4) # prepare screen 4 for output tsplot(corn.yield, ylab="yield in bushels/acre") screen(1, F) #return to screen 1, but do not clear tsplot(window(corn.yield, start(corn.yield), end(corn.yield)), axes = F, lty = 2) # overlay second plot axis(4) # add tic marks to right-hand axis title("Rainfall and Corn Yield in six Cornbelt States")

#Example 3 # decide the positioning of screens interactively split.screen(prompt.screen())