[R] Adding points sequentially to multiple graphs in one window (device)
Greg Snow
Greg.Snow at imail.org
Wed Aug 11 21:31:03 CEST 2010
The simplest thing to do is just recreate the plot(s) from scratch at each iteration with all the accumulated data. Most graphics devices are fast enough now that you will not notice the redraw. If you really just want to add to the plots, you can save and restore the graphics parameters, something like:
par(mfrow=c(2,1),mar=c(4,4,1,1))
plot(1:40,1:40,type='n')
p1 <- par(no.readonly=TRUE)
plot(1:20,1:20,type='n')
p2 <- par(no.readonly=TRUE)
par(p1); par(mfg=c(1,1)); points(15,5) # this plots incorrectly
par(p2); par(mfg=c(2,1)); points(15,5) # this plots correctly
hope this helps,
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of elinder at unh.edu
> Sent: Wednesday, August 11, 2010 12:50 PM
> To: r-help at r-project.org
> Subject: [R] Adding points sequentially to multiple graphs in one
> window (device)
>
> Dear R-help list:
>
> I have want seems to be a simple task, but can't find a solution.
> I tried querying the archives, but did not succeed.
>
> My goal is to set up two (or more) graphs in one graph window, and
> then during execution of a sequential algorithm add points
> sequentially to these graphs. The graphs have different scales
> / coordinates. I use the par(mfg...) command to
> switch between graphs. The problem is:
> This only plots points correctly in the
> last of the graphs. When I try to add a point to say the first
> graph, it is incorrect, namely it plots that point relative to
> the coordinate system of the last graph, not the first graph.
>
> How can I avoid this problem?
>
> I work with older and newer versions of R and both on Windows XP
> and on Mac OS.10.5.
>
> Here is a simple script to illustrate my dilemma:
>
> par(mfrow=c(2,1),mar=c(4,4,1,1))
> plot(1:40,1:40,type='n')
> plot(1:20,1:20,type='n')
> par(mfg=c(1,1)); points(15,5) # this plots incorrectly
> par(mfg=c(2,1)); points(15,5) # this plots correctly
>
>
> Any help or pointers would be greatly appreciated.
>
>
> Ernst Linder
>
> --
> Ernst Linder elinder at unh.edu
> Professor of Statistics
> Dept. of Mathematics and Statistics
> University of New Hampshire
> Phone: 603 862 2687 (work)
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list