[R] trellis/lattice: How to plot 4 panels with the same x-scale but different y-scales?

Marius Hofert m_hofert at web.de
Thu May 6 08:46:42 CEST 2010


Dear R experts,

I have four plots I would like to plot attached to each other (in panels). 
All plots have the same x-scale, but different y-scales. The example below shows 
pretty much what I would like to have, except that for the two plots in the
"second column" (of this 2x2 plot-matrix), I would like to have the y-ticks 
shown on the right side such that the four plot panels are attached to each other/glued
together. How can I achieve this?
I found a solution for a 2x1 matrix in the R-help archive, but this problem here is different.

Cheers,

Marius

Ps: I guess the "scales=..." should somehow go inside the panel function, so that
the panel number tells the "alternating"-argument where it has to print the ticks.

library(lattice)
x=rep(c(1,2,3),4) # x values
y=1:12 # y values
z=rep(1:4,each=3) # panel number
xyplot(y~x|z,type="l",aspect=1,layout=c(2,2),
        scales=list(y=list(relation="free"),alternating=c(1,1),tck=c(1,0)),
        panel=function(...){
                panel.xyplot(...,col=1)
                           
        }    
)


More information about the R-help mailing list