[R] basic question about changing limits on generated plots
Marc Schwartz
MSchwartz at MedAnalytics.com
Thu Feb 24 02:19:37 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)
>
> 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 C&P it or source() it
or use ESS.
HTH,
Marc Schwartz
More information about the R-help
mailing list