[R] basic question about changing limits on generated plots

rif rif at MIT.EDU
Thu Feb 24 03:14:50 CET 2005


> On Wed, 2005-02-23 at 17:42 -0500, rif wrote:
> > Is it possible to change the limits on plots that are already on the
> > screen?  In particular, is there any R equivalent to the sequence of
> > matlab commands
> > 
> > plot(1:10,1:10)
> > hold on
> > plot(2:12,5:15)
> > 
> > rif
> 
> I have not used Matlab, but I suspect that you want to use:
> 
> par(new = TRUE)
> 
> For example:
> 
> > plot(1:10,1:10)
> 
> # Check plot region limits
> > par("usr")
> [1]  0.64 10.36  0.64 10.36
> 
> # Set par("new") to not overwrite existing plot
> > par(new = TRUE)
> 
> > plot(2:12,5:15)
>
> Marc Schwartz

Marc,

This does not do what the matlab code I posted does (the matlab code
also works in the free program octave, if you want to try).  The
matlab code moves already plotted data within the window (replots it).
When I first type plot(1:10,1:10), I see a graph with axis limits [1
10 1 10].  When I type hold on (to keep my original data), and execute
plot(2:12,5:15), the plot I see is equivalent to the plot I'd have
gotten if I'd originally specified axis limits [1 12 5 15].  By
contrast, in the R code you sent, it's as if I'm superimposing two
unrelated plots.

Essentially, the underlying "task" is that I want to compare multiple
functions, but I do not know good limits for the complete set of
functions when I start.  Being able to adjust the graph to show all
the data I've plotted so far would be extremely useful for exploratory
analysis.  This is the mode I and colleagues generally use matlab and
octave in.

Does this question get asked all the time?  It seems to be something
that would come up a lot for people who switch from Matlab/Octave to
R, but I searched the archives and didn't really see anything.

Cheers,

rif




More information about the R-help mailing list