Reputation: 2293
It is easy to change the default strip height for lattice
plots: the par.strip.text
argument is all that one needs. But is there a simple way to to have strips of different heights within one multi-panel lattice plot?
I have in mind a plot with two rows of panels. The height of the strips in the first row would differ from the height of the strips in the second row.
I think that I can create such a figure by creating two plots –– one for the first row, another for the second row –– and then using grid.layout
to position them. But I'd like to know if there is a more straightforward way to create such a figure.
Upvotes: 2
Views: 1127
Reputation: 173697
I modified an example from this question (which is a much closer duplicate) and managed to achieve this:
bgColors <- c("black", "green4", "blue", "red", "purple", "yellow")
txtColors <- c("white", "yellow", "white", "white", "green", "red")
stripHt <- rep(c(-1,0),each = 3)
# Create a function to be passes to "strip=" argument of xyplot
myStripStyle <- function(which.panel, factor.levels, ...) {
panel.rect(0, stripHt[which.panel], 1, 1,
col = bgColors[which.panel],
border = 1)
panel.text(x = 0.5, y = 0.5,
font=2,
lab = factor.levels[which.panel],
col = txtColors[which.panel])
}
xyplot(yield ~ year | site, data = barley, strip=myStripStyle)
Ignore the horrible colors. You get the point, we're just using a custom strip function.
Upvotes: 5