[R] lattice: aligning independent graphs

Zack Weinberg zack at cogsci.ucsd.edu
Sun May 27 01:39:56 CEST 2007


I find myself wanting to plot three graphs side by side 'as if' they
were panels -- that is, with the same y-axis limits, no space between
the graphs, and precise vertical alignment of the plot areas. However,
I don't want strip titles; I want each graph to have its own x-axis
label, on the bottom of the plot.

The best way I have so far found to do this is to fake up a data frame
that allows me to use actual panels, turn off the strip, and insert a
whole bunch of white space in the x-axis label so it looks like there
are three separate labels.  Like this:

xyplot(x ~ thing | panel,
       data=wrong.all,
       ylab=list(label='% incorrect responses', cex=0.7),
       xlab=list(label=paste('Trial number                                 ',
                             'Subject number                              ',
                             'Experimental condition'), cex=0.7),
       ylim=c(0,top), col='black', pch=3, strip=F,
       scales=list(
         x=list(alternating=c(1,0), tck=c(1,0), cex=0.5, rot=90,
           relation='free',
           at=list(
             seq(0,33,by=5),
             seq(0,maxsub, by=5),
             seq(1,length(levels(wrongconds)))),
           labels=list(seq(0,33,by=5), seq(0,maxsub, by=5),
             levels(wrongconds))),
         y=list(at=seq(0,top,by=10), alternating=c(1,0),
           tck=c(1,1),
           cex=0.5)),
       type=list(c('p','smooth'), 'h', 'h'),
       panel=function(..., type=list("p")) {
         panel.grid(h=-1, v=0)
         panel.xyplot(..., type=type[[panel.number()]])
       })

But surely there is a better way?

zw



More information about the R-help mailing list