[R] plot scale

Duncan Murdoch murdoch at stats.uwo.ca
Fri Oct 2 11:10:09 CEST 2009


On 02/10/2009 4:07 AM, Ben Kenward wrote:
> Hi,
> 
> Is there a way to set the scale of a plot (i.e. number of axis units
> per centimeter) when you output it to postscript? If not, how am I
> supposed to plot graphs with different axis limits to the same scale?
> They just get resized to fit the paper so that graphs which show a
> smaller number of axis units end up with a larger scale.

I don't think there's a simple way to specify the exact relationship, 
but you can do it with some work.

When you open the postscript device, you can specify the size.  When you 
do a plot, you can specify the size of the margins, so that lets you 
indirectly specify the size of the plot region.  And of course you can 
specify the axis limits.

So the way I'd do what you want is as follows:  plot the data, use 
par("usr") to extract the axis limits, use par("mai") to extract the 
margin size.  Then calculate the size you want for the particular 
scaling, and open the postscript device with that size, reset par("mai") 
to the previous value, and repeat your plot.

Duncan Murdoch




More information about the R-help mailing list