[R] basic question about changing limits on generated plots

Marc Schwartz MSchwartz at MedAnalytics.com
Thu Feb 24 06:50:20 CET 2005


On Wed, 2005-02-23 at 21:14 -0500, rif wrote:

<snip>

> 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

A general statement: There are members of the R Community engaged in
Octave, so there is some overlap, at least in terms of expertise with
both tools. Perhaps they can offer some insight here.

The good news is that I have Octave installed on my FC3 system, so I was
able to get a feel for what you are referring to.

A search of the R archives would suggest that there is not a direct
parallel in terms of adding a new set of data to an existing plot, while
having the entire coordinate system adjusted to the new data in a single
step.

There are references to what I suggested, the use of the 'add' argument
in some plot functions and of course the use of points() and lines().

I would defer to others with more low-level knowledge of the standard R
screen based plotting devices, but from my past review of code (both R
and C) and reasonable knowledge, I am not sure that this can be done
without some form of two step approach involving re-plotting the
original data using an updated coordinate system based upon the new data
and then overlaying the new data. Presumably at a low level, this is
what Octave and Matlab do, since I noted that the plot device seems to
be completely re-drawn upon the second plot call. Since Octave is open
source, one can of course review the code to see what is truly
happening.

The key it seems would be to "transparently" save the original data as
an object, re-plot it with the adjusted coordinate system and then add
the new data. 

I would guess that with some thought, one could create some wrapper
plotting functions or methods that would save the data object(s) in a
plot "environment" so that each successive plot call "layers" the older
data sets in turn and then add the newest data set. All this done in a
coordinate system that is re-configured each time, based upon the
maximum x and y axis ranges required for the multiple datasets that have
been plotted to that point.

Almost sounds like a plot "stack", to use an assembly language metaphor.

You might also want to look at the xgobi package on CRAN, which provides
an interface to the XGobi system:

http://www.research.att.com/areas/stat/xgobi/

or the ggobi system:

http://www.ggobi.org/

which is accessible from R. These are both dynamic data visualization
tools.

HTH,

Marc




More information about the R-help mailing list