Re: [R] basic question about changing limits on generated plots

2005-02-24 Thread Jan T. Kim
On Wed, Feb 23, 2005 at 09:14:50PM -0500, rif wrote:

 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.

FWIW, I use constructs such as

plotfuncs - function(x, func, ...)
{
  y - as.list(1:length(func));
  for (i in 1:length(func))
  {
y[[i]] - sapply(x, func[[i]]);
  }
  xlim - c(min(x), max(x));
  ylim - c(min(sapply(y, min)), max(sapply(y, max)));
  plot.new();
  plot.window(xlim, ylim, ...);
  for (i in 1:length(func))
  {
lines(x, y[[i]]);
  }
  axis(1, ...);
  axis(2, ...);
  box(...);
}

plotfuncs(1:100 / 100, list(sqrt, log, exp))

which allows you to add further functions incrementally, as in

plotfuncs(1:100 / 100, list(sqrt, log, exp, function(x) {3 / (x + 1)}))

Perhaps, that's what you have in mind, and probably, that's what (some)
others do...

Best regards, Jan
-- 
 +- Jan T. Kim ---+
 |*NEW*email: [EMAIL PROTECTED]   |
 |*NEW*WWW:   http://www.cmp.uea.ac.uk/people/jtk |
 *-=  hierarchical systems are for files, not for humans  =-*

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] basic question about changing limits on generated plots

2005-02-23 Thread Marc Schwartz
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)
 
 I know I can use points and lines to add points and lines to plots,
 but the limits of the plot do not change when I do this.
 
 Looking at various examples, it seems that the answer is no, but I
 wanted to make sure.  This seems to make exploratory data analysis
 somewhat more challenging.
 
 It also seems like it would be plausible to write a package on top of
 the standard graphics functions that keeps track of what you've done
 and automatically replots.  Which makes me think, has someone already
 done this?
 
 Cheers,
 
 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)

# Re-check plot region limits
 par(usr)
[1]  1.6 12.4  4.6 15.4

See ?par for more information.

Note also that par(usr) is not read-only, so you can explicitly change
it when required:

 plot(1:10,1:10)

 par(usr)
[1]  0.64 10.36  0.64 10.36

# Now reset the plot region limits
 par(usr = c(0, 20, 0, 20))

# Check it
 par(usr)
[1]  0 20  0 20


You do not indicate what OS you are using, but Under Windows, there is
an ability to record plots. See R Windows FAQ 4.2. Otherwise, save the R
code that you use to generate the plot and either CP it or source() it
or use ESS.

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] basic question about changing limits on generated plots

2005-02-23 Thread rif

 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

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] basic question about changing limits on generated plots

2005-02-23 Thread Marc Schwartz
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

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html