[R] FW: Aligning different trellis plots
Wiener, Matthew
matthew_wiener at merck.com
Tue Apr 20 21:31:06 CEST 2004
All --
I am trying to combine trellis plots and having a couple of small problems.
I'm trying to combine two trellis plots that display data of different
kinds. Each has a single row of plots, and I'd like to display them over
one another. So I use
print(plot1, split = c(1,1,2,1), more = TRUE)
print(plot2, split = c(1,2,1,2))
I end up with two minor issues. First, I'd like to have the top of the
bottom plot touch the bottom of the top plot, so it all looks like one plot
(I'd turn off the strip in the bottom one). I've turned off the x labels
and bottom axes for the top plot, but there still ends up being some space
between them. The effect I'm looking for is like setting various components
of "mar" to 0 in base graphics, but I can't figure out how to do it.
The second issue has to do with axes. My two plots have the same number of
panels across, and I would like them to line up vertically. However, my
y-axis labels, on the left of each plot, are slightly different size, and
this means that the panels are of slightly different sizes in the two plots.
Here's a toy example that shows my two problems.
df.1 <- data.frame(x = rep(1:10, 5),
y = runif(50, 0, 10),
group = rep(1:5, each = 10))
df.2 <- data.frame(x = rep(1:10, 5),
y = runif(50, -1, 1),
group = rep(1:5, each = 10))
plot.1 <- xyplot(y ~ x | group, data = df.1,
scales = list(x = list(alternating = 0),
y = list(alternating= 1)),
xlab = "", ## same results with
xlab = NULL
layout = c(5,1,1))
plot.2 <- xyplot(y ~ x | group, data = df.2,
scales = list(alternating = 1),
layout = c(5,1,1))
print(plot.1, split = c(1,1,1,2), more = TRUE)
print(plot.2, split = c(1,2,1,2))
I realize that it could be the xlab = "" that is giving me trouble -- it may
still be reserving space. But xlab = NULL does the same thing, and I
haven't been able to find anything else to try.
One moderately ugly way to solve the problem is to use position instead of
split in the print statement for the trellis plots, and use overlapping
ranges to force the bottom of the top plot to line up with the top of the
bottom plot. But it would be nice to have something a little more
automatic.
Or is there some better way to do this altogether -- perhaps that would
force a single plot to contain two kinds of panels? That seems to really go
against the principle of lattice graphics, though.
Thanks for any help.
Regards,
Matt Wiener
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments,...{{dropped}}
More information about the R-help
mailing list