0

Using the lattice package in R, I would like to plot one row of 7 diagrams, all using the same Y-axis. The diagrams should be (vertical) line diagrams. The problem is that my data are each in 7 separate dataframes (containing X and Y data), with different slightly different limits on the Y-axis data.

Besides all tutorials, I don't get it right. What must my Code look like? Is there even a clean solution for this in lattice?

Arne
  • 167
  • 7
  • 1
    Maybe this will help http://stackoverflow.com/questions/23928834/different-scales-of-multipanel-plots-using-lattice-package-in-r – FlorianSchunke Aug 09 '16 at 12:28

1 Answers1

1

You could combine all your data frames into one and then do something like

xyplot(Y~X|odf,data=combinedDF,layout=c(7,1))

where odf is an indicator column of the original data frame. This by default should use a common y scale.

Apart from combining the data, you could create 7 separate plots, then print them.

p1 <- xyplot(Y~X,data=DF1,ylim=c(Y1,Y2))
p2 <- xyplot(Y~X,data=DF2,ylim=c(Y1,Y2))
etc.

To print:

print(p1,split=c(1,1,7,1),more=TRUE)
print(p2,split=c(2,1,7,1),more=TRUE)
...
print(p7,split=c(7,1,7,1),more=FALSE)

see ?print.trellis.

Of course, arranging single plots like this doesn't really use the features of lattice. You could just as easily do this with base graphics using layout or par(mfrow=c(1,7)) for example, and a common ylim.

DaveTurek
  • 1,297
  • 7
  • 8