Skip to content

Multi-plot figures with different numbers of plots in different rows

7 messages · Hess, Stephane, Federico Calboli, Anne York +2 more

#
On Sat, 2005-03-26 at 17:44 +0000, Hess, Stephane wrote:
There is a book called `Gr?ficos Estad?sticos con R' under "contributed
documentation" in the main R website. It should prove useful. The book
is in spanish, but as it is a "graphical" manual, it should not matter
much. If in troubles email me privately.

Cheers,

Federico
#
On Sat, 26 Mar 2005, Hess, Stephane wrote:
HS > Dear all, 
HS > 
HS > I have 5 plots that I would like to include in a single figure, spread over two rows. If I use mfrow=c(2,3), and produce my plots one after the other, I will end up with three plots in the first row, and 2 in the second row, which is what I want. However, I would like the two plots in the second row to be moved to the centre of that row, rather than occupying the two left-most cells.
HS > 
HS > I have also considered using split.screen, but this would mean that the plots in the lower half would be wider than in the upper half, whereas I want them all to be of the same size.
HS > 
HS > Thanks in advance for any suggestions on how this can be done.
HS > 
HS > Stephane
HS > 
HS > 
HS > --------------------------------------------------------------------------------------
HS > Mr Stephane Hess
HS > Centre for Transport Studies
HS > Imperial College London
HS > -------------------------------------------------------------------------------------- 


Here is a brute force way:

par(mfrow=c(2,3)) #set up 2 rows x 3 colums
plot(1:10) #plot 1
plot(1:10) #plot 2
plot(1:10) #plot 3
par(mfg=c(2,2))  # start next plot at 2,2 instead of 2,1
 plot(1:10)       # 4th plot
#
Hi
Hess, Stephane wrote:
> Dear all,
 >
 > I have 5 plots that I would like to include in a single figure,
 > spread over two rows. If I use mfrow=c(2,3), and produce my plots one
 > after the other, I will end up with three plots in the first row, and
 > 2 in the second row, which is what I want. However, I would like the
 > two plots in the second row to be moved to the centre of that row,
 > rather than occupying the two left-most cells.
 >
 > I have also considered using split.screen, but this would mean that
 > the plots in the lower half would be wider than in the upper half,
 > whereas I want them all to be of the same size.


Something like ...?

layout(rbind(c(1, 1, 2, 2, 3, 3),
              c(0, 4, 4, 5, 5, 0)))
for (i in 1:5) {
   plot(i, type="n")
   text(1, i, paste("Plot", i), cex=4)
}

Paul
2 days later
#
"Anne York" <york at zipcon.net> wrote in message
news:Pine.LNX.4.62.0503261316330.2758 at sasquatch...
If you want to leave the last plot(s) in a such a figure blank,
and continue on with another figure, how does that work?

For example:

par(mfrow=c(2,3)) #set up 2 rows x 3 columns
plot(1:10, main="Plot 1")
plot(1:20, main="Plot 2")
plot(1:30, main="Plot 3")
par(mfg=c(2,2))  # start next plot at 2,2 instead of 2,1
plot(1:40, main="Plot 4")

# What if 5th plot is to start on next page?
# Why do plots 5 and 6 overlay plots 1 and 2 instead
# of being on a new page?
par(mfg=c(1,1))
plot(1:50, main="Plot 5")
plot(1:60, main="Plot 6")

If "par(mfg=c(1,1))" is left out, Plot 6 is on the next figure.

The "new=T" parameters seems like a possible solution, but gives this
warning and is ignored:
     Warning messages:
     1: parameter "new" couldn't be set in high-level plot() function

par(mfrow=c(2,3)) #set up 2 rows x 3 columns
plot(1:10, main="Plot 1", new=T)
plot(1:20, main="Plot 2")
plot(1:30, main="Plot 3")
par(mfg=c(2,2))  # start next plot at 2,2 instead of 2,1
plot(1:40, main="Plot 4")

# What if 5th plot is to start on next page?
# Why do plots 5 and 6 overlay plots 1 and 2 instead
# of being on a new page?
par(mfg=c(1,1))
plot(1:50, main="Plot 5", new=T)
plot(1:60, main="Plot 6")

How do I create a series of plots in one figure and control
when a new figure is created? (without using dummy blank placeholder plots)

The example above is only for discussion.  I really want to do this in a
loop
and create 5 plots per figure, and repeat this for many pages in a PDF file.

Thanks for any insight on this.

efg
--
Earl F. Glynn
Scientific Programmer
Stowers Institute for Medical Research
#
Hi
Earl F. Glynn wrote:
Does this do what you want?

layout(rbind(c(1, 2, 3),
              c(0, 4, 0)))
plot(1:10, main="Plot 1")
plot(1:20, main="Plot 2")
plot(1:30, main="Plot 3")
plot(1:40, main="Plot 4")
# new page!
plot(1:40, main="Plot 5")

Paul
#
"Paul Murrell" <p.murrell at auckland.ac.nz> wrote in message
news:<4249D8B7.9070702 at stat.auckland.ac.nz>...
Yes, that works nicely.  Thank you very much.

I tried this wrapped with a pdf/dev.off and it works great:

pdf("test.pdf")
  <plot statements here>
dev.off()

I guess I should always use layout and avoid using mfrow or mfcol, since
it's more flexible in general.

I can't decide if the existing behavio(u)r of mfrow/mfcol is a "bug" or a
"feature" when some plots are to be left blank, and one wants to advance to
the next figure.  With your solution, I won't need to care <g>.  Thanks.

efg