[R] Multi-line plots with matrices in R

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed Mar 7 17:25:10 CET 2007


On Wed, 2007-03-07 at 15:11 +0000, Joseph Wakeling wrote:
> Gavin Simpson wrote:
> > You want maplot here. See ?matplot  but here is an example:
> 
> Great!  Thanks to you and Petr for pointing this out, it's exactly what
> I wanted.  Petr's other suggestions look interesting and I'll explore
> them at length later.
> 
> > Note the changed axis range in the right-hand margin. The problem is
> > that you can't use plot.window to achieve what you want, not that
> > plot.window doesn't do anything.
> 
> Ahhh, I see.  So, it does not affect what has already been plotted, but
> affects how new material is inserted into the plot area.  Entering
> 
> plot.window(xlim=c(0,100),ylim=c(0,0.5))
> axis(1)
> axis(2)
> plot.window(xlim=c(0,100),ylim=c(0,1))
> axis(2)
> 
> ... is instructive. :-)
> 
> So, _is_ there a command which will rearrange the existing plotted
> items, including axes?  Or does R require that I have a good idea of the
> space in which I want to plot from the start?

Not with the standard R graphics - think of the graphics window as a
piece of paper and if you draw anything on it you have done so in
permanent ink. If something needs changing you need a new sheet of paper
and have to redraw the lot. Most people I know write their code in some
text editor and send (or copy paste) it into R. It is an easy matter to
edit one or two bits of your code to tweak the display and re-plot...

I think you can modify lattice graphics objects and just plot (print
really) them again - but again you are really redrawing the whole plot
from scratch. IIRC grid might be able to do some of what you are looking
for.

> 
> Oh, and a quick cosmetic query---I notice that the axes when created are
> spaced apart somewhat so the axis lines do not meet at the plot origin.
>  Is there a way to alter this so that the outline of the box, and the
> extreme values of the axis, match up?
> 

Look at ?par and xaxs and yaxs. E.g.

plot(1:10, xaxs = "i", yaxs = "i")

G

> Thanks again,
> 
>     -- Joe
> 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Gavin Simpson                 [t] +44 (0)20 7679 0522
 ECRC, 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