[R] How to add separate labels to the axes of each panel plot?

Marius Hofert m_hofert at web.de
Sat May 8 15:35:34 CEST 2010


Dear all, 

I finally solved my problem. Here is a solution:

library(lattice)
library(grid)
x=c(1,2,1,2,1,2,1,2)
y=c(1,2,2,1,1,-1,-2000,2000)
z=c("z1","z1","z2","z2","z3","z3","z4","z4") 
xlabs=c("x_1","x_2","x_3","x_4")
xyplot(y~x|z,type="l",aspect=1,layout=c(2,2),as.table=TRUE,
       scales=list(relation="free",alternating=c(1,1),tck=c(1,0),y=list(rot=0)),
       par.settings=list(clip=list(panel=FALSE),
       layout.widths=list(axis.panel=2),
       layout.heights=list(axis.panel=2)),
       xlab="",ylab="",
       panel=function(...){
               panel.xyplot(...,col=1)
               grid.text(xlabs[panel.number()],x=unit(0.5,"npc"),y=unit(-0.24,"npc"))
       }    
)

Cheers,

Marius


More information about the R-help mailing list