[R] Write text in the

Martin Maechler maechler at stat.math.ethz.ch
Sat Apr 28 15:52:22 CEST 2007


>>>>> "Matt" == Matthew Neilson <matt at gneilson.plus.com>
>>>>>     on Fri, 27 Apr 2007 15:54:20 +0100 writes:

    Matt> Hey Felix,
    Matt> So basically what you want is a figure containing a block of four plots, with a main title for the figure? If that's the case then something like this should work:

    Matt> # BEGIN CODE #

    Matt> par(oma=c(0,0,1,0), mfrow=c(2,2))
    Matt> for(i in 1:4){
    Matt> plot(NA,xlim=range(0,10),ylim=range(-5,5))
    Matt> title(paste("Plot ",i,sep=""))
    Matt> }

    Matt> par(mfrow=c(1,1), oma=c(0,0,1,0))
    Matt> mtext("Main Title", 3, outer = TRUE, cex = par("cex.main"))

    Matt> # END CODE #


    Matt> You can play about with the margins, but I think that's the general idea. Is this what you're after?

Yes, and since this is so often desired, with our "sfsmisc"
package, you can simply say

  sfsmisc::mult.fig(4, main = "Main Title")
  for(i in 1:4){
      plot(NA,xlim=range(0,10),ylim=range(-5,5))
      title(paste("Plot ",i,sep=""))
  }

If you're a good R-citizen, you will want to be able to reset
the graphics parameters, which would extend the above to

  op <- sfsmisc::mult.fig(4, main = "Main Title") $ old.par
  for(i in 1:4){
      plot(NA,xlim=range(0,10),ylim=range(-5,5))
      title(paste("Plot ",i,sep=""))
  }
  par(op)

--
Martin Maechler, ETH Zurich


    Matt> On Fri Apr 27 15:34 , Felix Wave <felix-wave at vr-web.de> sent:

    >> Hello,
    >> I started a graphic device:
    >>> par(oma = c(2,0,0,0), mfrow=c(2,2) )
    >> 
    >> in the cols and rows are three "image"s.
    >> Now I want to write a text in the "device region", it's the
    >> main title of the graphic device. But when I use "mtext()" I can
    >> only write in the "figure region" of my four plots.
    >> 
    >> Has anybody an idea?
    >> 
    >> Thanks a lot.
    >> 
    >> Felix
    >> 
    >> 
    >> 
    >> My R Code:
    >> ----------
    >> par(oma = c(2,0,0,0), mfrow=c(2,2) )
    >> 
    >> mtext("Main title", side = 3, line = 0)
    >> 
    >> image(zDIV)
    >> image(zMEDIAN )              
    >> image(zMEAN) 
    >> image(zSD)  
    >> dev.off() 
    >> 
    >> 
    >> 
    >> graphic:   
    >> 
    >> -------------------------------------------
    >> |	MAIN TITLE   device region	   
    >> -------------------------------------------
    >> |   figure region    |   figure region    |
    >> |  --------------    |    ------------    |
    >> |  |		|    |	  |	     |	  |
    >> |  |		|    |    |	     |    |
    >> |  |		|    |	  |	     |	  |
    >> |  |		|    |    |	     |    |
    >> |  --------------         ------------    |
    >> |					  |	      
    >> -------------------------------------------
    >> |   figure region    |   figure region    |
    >> |  --------------    |    ------------    |
    >> |  |		|    |	  |	     |	  |
    >> |  |		|    |    |	     |    |
    >> |  |		|    |	  |	     |	  |
    >> |  |		|    |    |	     |    |
    >> |  --------------         ------------    |
    >> |					  |
    >>



More information about the R-help mailing list