[R] one problem about how to hold graphic with R

Gavin Simpson gavin.simpson at ucl.ac.uk
Tue Oct 31 15:33:18 CET 2006


On Tue, 2006-10-31 at 22:12 +0800, yang baohua wrote:
> Thanks 
> your reply is helpful
> but i want to draw two graphics on one window to compare them
> so i want to draw one then draw another with different color on the
> same window
> Can you tell me how to do so
> Waiting for your kind reply

Please reply-all to ensure others on the list see the full thread.

Again, it is not clear exactly (but that's me being dense probably) what
you want. I see two options:

1) Side by side plots

par(mfrow = c(1, 2))
plot(rnorm(100), rnorm(100))
plot(runif(100), rnorm(100), col = "red")
par(mfrow = c(1, 1))

or

2) overplotting one set of points on another

plot(rnorm(100), rnorm(100))
points(runif(100), rnorm(100), col = "red")

If 1), see ?par (and ?layout and ?split.screen for alternative ways to
splitting up a plotting device into n plotting regions), and if 2),
see ?points and ?lines, and I strongly suggest you read the R manual "An
Introduction to R" that came with R, especially section 12 on Graphics.

HTH

G

> 
>  
> 2006/10/31, Gavin Simpson <gavin.simpson at ucl.ac.uk>: 
>         On Tue, 2006-10-31 at 21:36 +0800, yang baohua wrote:
>         > Sorry to disturb you, but can you help me to solve one
>         little problem? 
>         > I want to draw a graphic after another with R
>         > but I cannot find the first one after that.
>         > Do you know the command to hold the graphic with R?
>         > I remember with Matlab you may use "hold on". 
>         > Thanks.
>         >
>         >
>         
>         You don't say which OS. On MS Windows one can turn on a
>         history of plots
>         to the graphics device and replay your plots - it is in the
>         menu bar for
>         example.
>         
>         In all OSes, you can start up a new device to take the plot -
>         which is 
>         what Matlab does IIRC, so you have two or more plot windows on
>         screen at
>         any one time. This is done like this:
>         
>         plot(1:10)
>         x11()
>         plot(1:20)
>         x11()
>         plot(rnorm(100))
>         
>         see ?Devices
>         
>         You can set a device to be active, i.e. switch around between
>         plotting
>         windows using dev.set(), e.g.:
>         
>         > dev.cur() # example from above leaves device 4 active
>         X11
>         4
>         > dev.set(3) # switch to device
>         > dev.cur() # check
>         X11
>         3
>         > plot(sort(rnorm(100))) # plot something new on this device
>         
>         Is this what you were looking for?
>         
>         HTH
>         
>         G
>         --
>         %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~
>         %~%~%~%
>         Gavin Simpson                 [t] +44 (0)20 7679 0522 
>         ECRC & ENSIS, UCL Geography,  [f] +44 (0)20 7679 0565
>         Pearson Building,             [e]
>         gavin.simpsonATNOSPAMucl.ac.uk
>         Gower Street, London          [w]
>         http://www.ucl.ac.uk/~ucfagls/
>         UK. WC1E 6BT.                 [w]
>         http://www.freshwaters.org.uk
>         %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~
>         %~%~%~%
>         
> 
> 
> 
> -- 
> Baohua Yang
> Department of Automation, Tsinghua University
> 228A, Zijing Bldg. No.2, Tsinghua Univ.
> Beijing, 100084, P.R.China 
> Tel. 010-51532228
> Email:yangbaohua at gmail.com 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Gavin Simpson                 [t] +44 (0)20 7679 0522
 ECRC & ENSIS, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list