[R] Aspect ratio and limits

Deepayan Sarkar deepayan at stat.wisc.edu
Tue Apr 19 19:11:36 CEST 2005


On Tuesday 19 April 2005 11:40, Barry Rowlingson wrote:
> Marc Schwartz wrote:
> > # Set height value as you require
> > height <- 3
> > X11(width = aspect * height, height = height)
> > ....
> > Does that get you what you need?
>
>   I'm guessing that will work, but it just seems unsatisfactory,
> since if I resize my graphics window I mess it up.
>
>   If I set par(pty='s') I can have a square plot floating inside a
> graphics window of any shape, I'd like to be able to plot something
> specifying ylim and asp and get a rectangular plot with a fixed
> aspect ratio floating around inside a resizable graphics device....
>
>   The 'aspect' ratio of xyplot (lattice package) lets you specify the
> aspect ratio of the plot (not relating to the data, ie aspect=1 draws
> a square plot whatever the ratio of X and Y range). Try this:
>
>   xy=data.frame(x=c(0,21),y=c(0,4))
>   xyplot(y~x,data=xy,aspect=0.2)
>
>   - now resize the graphics window and the plot keeps its ratio.
> That's the effect I was hoping to get from base graphics.
>
>   I could use lattice graphics but I'd have to work out the value of
> 'aspect' to get the 1:1 aspect ratio for my data. I'm not sure this
> is trivial, since it may involve considering the various margins and
> spacing around a plot.

Try (with a sufficiently recent version of R)

xyplot(y~x, data=xy, aspect="iso")

Is that what you want?

Deepayan




More information about the R-help mailing list