[R] positioning of separate y-axis labels in xyplot
    Benjamin Tyner 
    btyner at gmail.com
       
    Wed Jun 14 17:23:04 CEST 2006
    
    
  
I like the functionality provided by outer=TRUE, but when it comes time 
to place separate xlabs or ylabs, I always end up 'eyeballing' it on a 
case-by-case basis. For example,
##begin example
require(lattice)
cars.lo <- loess(dist ~ speed, cars)
print(xyplot(cars.lo$residuals+cars.lo$fitted~cars.lo$x,
             strip=FALSE,
             outer=TRUE,
             layout=c(1,2),
             ylab="",
             scales=list(y=list(relation="free",rot=0)),
             panel=function(x,y,panel.number,...){
                   if(panel.number==1){
                      panel.xyplot(x,y)
                      panel.abline(h=0)
                   }else{
                      panel.xyplot(x,y=cars.lo$y)
                      panel.xyplot(x,y,type="l")
                   }
             }))
require(grid)
trellis.focus("panel", 1, 1, clip.off=TRUE, highlight=FALSE)
grid.text("residuals", x=unit(0, "npc") + unit(-2, "lines"),rot=90)
trellis.focus("panel", 1, 2, clip.off=TRUE, highlight=FALSE)
grid.text("fitted", x=unit(0, "npc") + unit(-2, "lines"),rot=90)
## end example
In this case, a distance of -2 lines happens to be enough, but one has 
to make the plot to know this. I'm interested in learning how one can 
place the ylabs without fear of overlapping the tick labels; i.e., how 
to use the exact space allocated by ylab="". I'm thinking it must 
involve viewports?
Ben
    
    
More information about the R-help
mailing list