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. Cheers, Ben -- Dr. Ben Kenward Department of Psychology, Uppsala University, Sweden http://www.benkenward.com ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
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 ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
On Fri, Oct 2, 2009 at 11:10 AM, Duncan Murdoch <[hidden email]> wrote:
> I don't think there's a simple way to specify the exact relationship, but > you can do it with some work. Thanks Duncan. That's what I was beginning to suspect, nice to have confirmation, even if it will mean a bit of work. Ben -- Dr. Ben Kenward Department of Psychology, Uppsala University, Sweden http://www.benkenward.com ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
In reply to this post by Duncan Murdoch
Hi,
It looks like lattice or ggplot2 might make this easier, but I'm not entirely sure I understood the problem, short of an example. Best, baptiste 2009/10/2 Duncan Murdoch <[hidden email]>: > 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 > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
In reply to this post by amorphia
>
> 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. > > Cheers, > > Ben > If I understand you correctly, you want the units on each axis to be physically represented equally on the same scale. If this is right, try using the lattice package (xyplot, etc.) with aspect="iso". Lattice lets you adjust the aspect ratio of the plot to whatever you like and constrains the dimensions of the plot accordingly. Base graphics also allow for control of the aspect ratio using "asp=", but extend the limits of the plot to fill whatever region you are plotting in. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
In reply to this post by amorphia
Here is a different approach:
This example uses the default plotting device, but should work the same with postscript or any other device. Just set the size of the paper to a standard size, or a large enough size to fit your largest plot: dev.new() tmp <- par('plt') scale <- 5 x <- runif(100, 0, 20) y <- rnorm(100, x) dx <- diff(range(x))*1.08 wx <- grconvertX(dx/scale, from='inches', to='ndc') dy <- diff(range(y))*1.08 wy <- grconvertY(dy/scale, from='inches', to='ndc') par(plt = c(tmp[1], tmp[1]+wx, tmp[3], tmp[3]+wy) ) plot(x,y) dev.new() x2 <- runif(100, 0,5) y2 <- rnorm(100, x2) dx <- diff(range(x2))*1.08 wx <- grconvertX(dx/scale, from='inches', to='ndc') dy <- diff(range(y2))*1.08 wy <- grconvertY(dy/scale, from='inches', to='ndc') par(plt = c(tmp[1], tmp[1]+wx, tmp[3], tmp[3]+wy) ) plot(x2,y2) The above only works for 1 plot per page (no layout or par(mfrow=... ) ). This keeps the lower left corner of the plot in the same place (so change the margins before the call to par('plt') if you want them different). Then sets the top and right parts of the plotting region leaving white space on the top and right to get the scaling correct (you will have problems if your desired scale does not fit in the window/on the page). This example uses a "scale" of 5 plot units per inch, change as appropriate. The *1.08 is to account for the extra area that is added to the plot by default, change this for the other axis type. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [hidden email] 801.408.8111 > -----Original Message----- > From: [hidden email] [mailto:r-help-bounces@r- > project.org] On Behalf Of Ben Kenward > Sent: Friday, October 02, 2009 2:08 AM > To: [hidden email] > Subject: [R] plot scale > > 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. > > Cheers, > > Ben > > -- > Dr. Ben Kenward > Department of Psychology, Uppsala University, Sweden > http://www.benkenward.com > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Free forum by Nabble - Free Resume Builder | Edit this page |