[R] positioning of separate y-axis labels in xyplot

From: Benjamin Tyner <btyner_at_gmail.com>
Date: Thu 15 Jun 2006 - 01:23:04 EST


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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jun 15 01:28:09 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 23 Jun 2006 - 14:12:00 EST.

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