Re: [R] Misunderstanding with lines (or elsewhere)

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Wed 12 Jul 2006 - 00:34:11 EST

On Tue, 2006-07-11 at 15:39 +0200, vincent@7d4.com wrote:
> Prof Brian Ripley a écrit :
>
> > Think about the coordinate system you are using: if you don't set the
> > margins to zero you will see what it is.
> > I suggest you supply x and y to image() to set the coordinate system to
> > what you want it to be.
>
> Thank you for your answer.
> If I have well understood, the right way to proceed
> must be :
>
> test = function()
> {
> m = matrix(0, 2, 2)
> par(new=T, fig = c(0,1,0,1), mai=c(0,0,0,0), mar=c(0,0,0,0), bty='n')
> x0 = c(0.25 , 0.75)
> y0 = x0
> image(x=x0, y=y0, z=m)
> lines(c(0,1), c(1/4,1/4)) # horizontal line
> }
>
> which seems indeed to work.
> Thanks.

You could swap the line:

lines(c(0,1), c(1/4, 1/4))

with:

abline(h = 0.25)

Does the same thing but is more readable IMHO.

Also, I get a warning with your code if no plot is open:

Warning message:
calling par(new=) with no plot

To stop this, drop the new = T (sic) in the call to par. Also, don't use T when you mean TRUE.

So, in summary this seems to do the same thing as your function:

test = function()
{
m = matrix(0, 2, 2)
par(fig = c(0,1,0,1), mai=c(0,0,0,0), mar=c(0,0,0,0), bty='n') x0 = c(0.25 , 0.75)
y0 = x0
image(x=x0, y=y0, z=m)
abline(h = 0.25)
}

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/cv/
 London, UK. WC1E 6BT.         [w] http://www.ucl.ac.uk/~ucfagls/
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Jul 12 02:08:33 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 13 Jul 2006 - 18:14:11 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.