split.screen problem (PR#2069)

cbodily@att.net cbodily@att.net
Thu, 26 Sep 2002 19:37:42 +0200 (MET DST)

Full_Name: Chris Bodily
Version: 1.5.1
Submission from: (NULL) (

I took the following code directly from the 'split.screen' help page in R and
modified one line to highlight the problem I encountered.  Basically, it appears
that when plotting in split screens and attempting to return to a particular
screen to add or update points, the axes from the original plot are not
remembered, causing the new points to plot incorrectly.
A workaround seem to be storing the original plot range and issuing
'plot(x,y,type="n")' where x and y are data vectors with ranges that match the
original plot in the screen of interest.  Then a 'points' command draws in the
correct locations.
I found this by moving working code from S-Plus 2000 into R v1.5.1 and noticed
that a particular interactive plot I use began drawing incorrectly.
Chris Bodily
   if (interactive()) {
     par(bg = "white")           # default is likely to be transparent
     split.screen(c(2,1))        # split display into two screens
     split.screen(c(1,2),2)      # split bottom half in two
     plot(1:10)                  # screen 3 is active, draw plot
     erase.screen()              # forgot label, erase and redraw
     plot(1:10, ylab= "ylab 3")
     screen(1)                   # prepare screen 1 for output
     screen(4)                   # prepare screen 4 for output
     plot(1:10, ylab="ylab 4")
     screen(1, FALSE)            # return to screen 1, but do not clear
#     plot(10:1,axes=FALSE, pch=2,col=5, lty=2, ylab="")  # overlay second plot

## Problem here as the following points get plotted incorrectly ##
## it seems that the axes are reset                             ##
     points(rep(3,10),1:10,col=2,pch=2)  # add a few more points for a test
     axis(4)                     # add tic marks to right-hand axis
     title("Plot 1")
     close.screen(all = TRUE)    # exit split-screen mode

r-devel 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-devel-request@stat.math.ethz.ch