The title function does not always work properly when used to add a global title to a figure containing several plots.

Patrick Lindsey patrick.lindsey@luc.ac.be
Fri, 21 Jun 2002 18:54:44 +0200 (MET DST)


Hi everyone,
  The following problem occurs with R-1.5.1 on an Intel laptop running
RedHat 7.2, with R-1.5.0 on an Alpha server running OSF 4.0 and on a
SGI server running IRIX 6.5, and with version of R as old as 1.2.3 (I
only tried older version under RedHat 7.2 and R-1.2.3 is the oldest I
still currently have installed). The complete of these three different
platforms can be found at the end of my email.
  The problem is the following. I am trying to add a global title to a
figure which contains several plots. Although I am not convince the
method I am using (see below) is the best way to achieve this, I
noticed that it failed to add the title in certain cases but not in
others. I included below some examples where it works and where it
does not work for me. As the same behavior occurs on all three
platforms I have access to, I guess that everyone (perhaps not does on
MS-Windows or on a Mac) should be able to see the problem by running
my code (if this is not the case, please let me know and I shall
provide some postscript files illustrating the problem).
  Unfortunately, the c-code to print text to the graphic window is
very complex and I am not familiar with it. As I thought that the
problem was related with the "title" function, I started by looking at
the "do_title" subroutine (R_HOME/src/main/plot.c). From there, I went
to the "GText" subroutine (R_HOME/src/main/graphics.c) which appears
to call the subroutine "clipText" to print the text to the canvas (but
I could already be wrong about this...). But in any case, I was not
able to trace down the problem as each of these subroutines appears to
get entered as expected with parameters containing the expected values
but then "clipText" appears to call ((GEDevDesc*) dd)->dev->text(...)
which I longer understand... On the other hand, I no longer think that
the problem is actually coming from the "title" function but rather
from a global variable (or perhaps a "par" option) that is not always
reset (or initialized) properly... by at least functions such as
"title" and plot.default with options "axis", "ylab", "xlab", or
"main" when the option "mfrow" is not set to "c(1,1)" in the "par"
options.
  I hope that this is understandable... but in any case, the following
examples should clarify things up.

# OK
par(mfrow=c(2,2),oma=c(0,0,4,0))
plot(1:3,1:3,xlab="",ylab="",main="")
par(mfrow=c(1,1),oma=c(0,0,0,0))
title(main="This should be the title of this figure.")

# Not OK (global title not at all printed)
par(mfrow=c(2,2),oma=c(0,0,4,0))
plot(1:3,1:3,xlab="This is the x-axis label.",ylab="",main="")
par(mfrow=c(1,1),oma=c(0,0,0,0))
title(main="This should be the title of this figure.")

# Not OK (global title not at all printed)
par(mfrow=c(2,2),oma=c(0,0,4,0))
plot(1:3,1:3,xlab="",ylab="This is the y-axis label.",main="")
par(mfrow=c(1,1),oma=c(0,0,0,0))
title(main="This should be the title of this figure.")

# Not OK (global title not at all printed)
par(mfrow=c(2,2),oma=c(0,0,4,0))
plot(1:3,1:3,xlab="This is the x-axis label.",
     ylab="This is the y-axis label.",main="")
par(mfrow=c(1,1),oma=c(0,0,0,0))
title(main="This should be the title of this figure.")

# Not OK (global title not at all printed)
par(mfrow=c(2,2),oma=c(0,0,4,0))
plot(1:3,1:3,xlab="This is the x-axis label.",
     ylab="This is the y-axis label.",main="a)")
par(mfrow=c(1,1),oma=c(0,0,0,0))
title(main="This should be the title of this figure.")

# OK
par(mfrow=c(2,2),oma=c(0,0,4,0))
plot(1:3,1:3,xlab="This is the x-axis label.",
     ylab="This is the y-axis label.",main="a)",axes=F)
axis(1)
axis(2)
box()
par(mfrow=c(1,1),oma=c(0,0,0,0))
title(main="This should be the title of this figure.")

# Strange... but can perhaps help in identifying the problem.
par(mfrow=c(2,2),oma=c(0,0,4,0))
plot(1:3,1:3,xlab="This is the x-axis label.",
     ylab="This is the y-axis label.",main="a)")
par(mfrow=c(1,1),oma=c(0,0,0,0))
title(main="This should be the title of this figure.")
title(main="This should be the title of this figure.",outer=TRUE)
title(main="This should be the title of this figure.")

  Please, let me know if I can be of any further help in tracing down
the problem.

Thanks,
Patrick

PS: Note that there is for the moment a work around which is the
following:

# Work-around
par(mfrow=c(2,2),oma=c(0,0,4,0))
plot(1:3,1:3,xlab="This is the x-axis label.",
     ylab="This is the y-axis label.",main="a)")
par(mfrow=c(1,1),oma=c(0,0,0,0))
mtext("This should be the title of this figure.",line=2,font=2,cex=1.2)

-----------------------------------------------------------------

> R.version
         _                
platform i686-pc-linux-gnu
arch     i686             
os       linux-gnu        
system   i686, linux-gnu  
status                    
major    1                
minor    5.1              
year     2002             
month    06               
day      17               
language R                

> R.version  
         _                   
platform alphaev6-dec-osf4.0f
arch     alphaev6            
os       osf4.0f             
system   alphaev6, osf4.0f   
status                       
major    1                   
minor    5.0                 
year     2002                
month    04                  
day      29                  
language R                   

> R.version
         _               
platform mips-sgi-irix6.5
arch     mips            
os       irix6.5         
system   mips, irix6.5   
status                   
major    1               
minor    5.0             
year     2002            
month    04              
day      29              
language R               

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._