nouse
nouse

Reputation: 3461

Multiple plots in one panel: Layout(matrix) without stretching plots

So far, ive seen only solutions to plot multiple figures in one panel which are stretching one (or all) of the plots in the row with the uneven number:

m <- matrix(c(1,2,3,4,5,5 ), nrow = 2, ncol = 3, byrow=TRUE)
layout(m)
plot(rnorm(100))
plot(rnorm(100))
plot(rnorm(100))
plot(rnorm(100))
plot(rnorm(100))

The last subplot is stretched to the length of the remaining atrix row. Now, id like to have the two plots in the second row aligned in the center (like this: http://jpgraph.net/download/manuals/chunkhtml/images/matrix_layout_ex1.png for example).

Is this possible?

Upvotes: 0

Views: 718

Answers (1)

Roland
Roland

Reputation: 132706

You can't do this with layout. However split.screen is more flexible:

#split screen in two rows:
split.screen(c(2, 1))
#split first row in three columns:
split.screen(c(1, 3), screen = 1)
#split second row in two screens with specific dimensions:
split.screen(matrix(c(1/6, 0.5,  #left
                      0.5, 5/6,  #right
                      0, 0,      #bottom    
                      1, 1),     #top
                    ncol=4), 
             screen=2)

#now fill the screens
screen(3)
plot(rnorm(100))
screen(4)
plot(rnorm(100))
screen(5)
plot(rnorm(100))
screen(6)
plot(rnorm(100))
screen(7)
plot(rnorm(100))
close.screen(all = TRUE) 

resulting plot

Upvotes: 2

Related Questions