Reputation: 4077
I wish to create a plot in R that has 11 panels: three in a left-hand column, and eight in a right-hand column. I'd like the three left-hand plots to be the same height, and the eight right-hand plots to be the same height.
I can get some way using layout
and hacking the margins: but because it's not possible to specify negative margins, this doesn't allow me to use the full space in the left column. Moreover, margins may look different if the plot is later sent to a PDF device with a different page size.
layout(matrix(c(1, 1, 0, 2, 2, 0, 3, 3, 3 + (1:8)), ncol=2),
widths=c(0.33, 0.67))
par(mar=c(0, 2, 2, 2))
plot(c(1, 1))
par(mar=c(0, 2, 0, 2))
plot(c(1, 1))
par(mar=c(2, 2, 0, 2))
plot(c(1, 1))
par(mar=rep(2, 4))
for (i in 1:8) plot(c(2, 2), col='red')
Is there a way to do this such that the three left-hand plots are equally sized and spaced, and use all the available space?
(edit:) MichaelChirico has pointed out that I could use 8×3 rows, which is viable for this example, but becomes cumbersome when there are multiple columns with different numbers of rows; I believe that layout can only support up to 200 rows.
Upvotes: 1
Views: 431
Reputation: 145775
Here's an example using your code and split.screen
. Obviously you'll want to adjust the margins.
dev.off()
split.screen(figs = c(1, 2))
split.screen(figs = c(3, 1), screen = 1)
screen(n = 3)
par(mar=c(0, 2, 2, 2))
plot(c(1, 1))
screen(n = 4)
par(mar=c(0, 2, 2, 2))
plot(c(1, 1))
screen(n = 5)
par(mar=c(0, 2, 2, 2))
plot(c(1, 1))
split.screen(figs = c(8, 1), screen = 2)
for (i in 6:13) {
screen(n = i)
plot(c(2, 2), col='red')
}
Upvotes: 1