[R] grid.layout?

From: Patrick Connolly <p_connolly_at_slingshot.co.nz>
Date: Wed, 05 Mar 2008 08:26:57 +1300

platform       x86_64-unknown-linux-gnu    
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          2                           
minor          6.2                         
year           2008                        
month          02                          
day            08                          
svn rev        44383                       
language       R                           
version.string R version 2.6.2 (2008-02-08)

The following code does almost everything I want except the red rectangle should be aligned flush with square. There's something I haven't understood about the grid.layout function. The second time I use it, it does what I expect, but there's something wrong with the first one.

  require(grid)
  N <- 5
  variates <- LETTERS[1:N]

  grid.newpage()
  plot.square <- 2 * length(variates)# cm
  text.wid <- 3 # cm
  vp <- grid.layout(nrow = 1, ncol = 2,
                    widths = c(text.wid, plot.square),
                    heights = plot.square, default.units = "cm")
  pushViewport(viewport(layout = vp, layout.pos.row = 1,
                        layout.pos.col = 2))
  ##
  vpp <- grid.layout(nrow = length(variates),
                     ncol = length(variates),
                     widths = 2, heights = 2, 
                     default.units = "cm")
  pushViewport(viewport(layout = vpp))   

  for(i in seq(variates)){
    for(j in seq(variates)){

      pushViewport(viewport(layout = vpp, layout.pos.col = j,
                            layout.pos.row = i))
      grid.rect(gp=gpar(lty='dashed'))
      popViewport(1)

    }
}

  popViewport(1)
  pushViewport(viewport(layout = vp, layout.pos.col = 1,
                        layout.pos.row = 1))
  grid.rect(gp=gpar(col = "red", width = 3))
  ylab.pos <- seq(variates)/length(variates)   ylab.pos <- ylab.pos - ylab.pos[1]/2
  for(i in seq(variates)){
    grid.text(rev(variates)[i], x = 0.9, gp=gpar(cex = .8),
              y =  ylab.pos[i], default.units = "npc",
              just="right")

}
 

Suggestions about the more intelligent use of pushViewport and popViewport would also be appreciated.

Thank you.

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___    Patrick Connolly   
 {~._.~}          		 Great minds discuss ideas    
 _( Y )_  	  	        Middle minds discuss events 
(:_~*~_:) 	       		 Small minds discuss people  
 (_)-(_)  	                           ..... Anon
	  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 04 Mar 2008 - 19:30:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 04 Mar 2008 - 20:30:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive