[R] how to control the overall shape of a figure?

Marc Schwartz marc_schwartz at comcast.net
Tue Feb 17 04:36:17 CET 2009


on 02/16/2009 07:51 PM Oliver wrote:
> hi,
> 
> I am a R beginner. One thing I notice is that when do graphing is,
> 
> if I want to draw two figures in a row such as this:
> 
> par(mfrow(1, 2))
> plot(...)
> plot(...)
> 
> Each figure inside will be rectangle instead of the familiar square
> shape.
> Though you can drag the edge the window to resize it. I would have
> prefer this can be done automatically ... also when I do the pdf
> export for example. Is this possible?
> 
> The thing is if you do par (mfrow(2,2)), then you got all 4 figures in
> perfect square shape ... but one row two figures are pretty common to
> me.
> 
> thanks for help
> 
> Oliver

The overall shape of the plot region is controlled by par("pty"), which
is set to "m" by default, for 'maximal' plotting region.

Set this to "s" to create a square plot region. For example:

par(mfrow = c(1, 2), pty = "s")
plot(1)
plot(1)


In order to do this with a PDF file, ensure that the overall plot
dimensions are in the proper relative aspect ratio. For example:

pdf(file = "SquarePlots.pdf", height = 4, width = 8)
par(mfrow = c(1, 2), pty= "s")
plot(1)
plot(1)
dev.off()

This will create 2 square plots, side-by-side, within an overall plot
size of 4x8. You can further adjust the plot margins and other
characteristics as may be required.

See ?par and ?Devices for more information regarding these
customizations and options to set size arguments for specific devices.

HTH,

Marc Schwartz




More information about the R-help mailing list