[R] basic question about changing limits on generated plots
Jan T. Kim
jtk at cmp.uea.ac.uk
Thu Feb 24 12:35:49 CET 2005
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: jtk at cmp.uea.ac.uk |
| *NEW* WWW: http://www.cmp.uea.ac.uk/people/jtk |
*-----=< hierarchical systems are for files, not for humans >=-----*
More information about the R-help
mailing list