[R] Vertical Line on Plot

2006-05-25 Thread Peter Lauren
I was wondering what would be the best way to put a
vertical line on a graph made with plot().  I can get
an horizontal line by plotting a vector where every
element has the same value but it is not as clear how
a vertical line should be done.

Thanks very much,
Peter.

__
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


Re: [R] Vertical Line on Plot

2006-05-25 Thread Barry Rowlingson
Peter Lauren wrote:
 I was wondering what would be the best way to put a
 vertical line on a graph made with plot().  I can get
 an horizontal line by plotting a vector where every
 element has the same value but it is not as clear how
 a vertical line should be done.


  abline(v=42)

you can use it for horizontal lines too: abline(h=42) and several other 
things. See help(abline) for details.

Barry

__
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


Re: [R] Vertical Line on Plot

2006-05-25 Thread Gavin Simpson
On Thu, 2006-05-25 at 09:26 -0700, Peter Lauren wrote:
 I was wondering what would be the best way to put a
 vertical line on a graph made with plot().  I can get
 an horizontal line by plotting a vector where every
 element has the same value but it is not as clear how
 a vertical line should be done.
 
 Thanks very much,
 Peter.

Is this what you want?

set.seed(12345) # reproducible random numbers
datx - rnorm(100) # some example data
daty - rnorm(100)
plot(datx, daty) # plot it
abline(v = mean(datx)) # add vertical line at mean of x
abline(v = 0.5, col = red) # same but at x == 0.5
abline(h = mean(daty)) # horizontal lines
abline(a = 0, b = 1) # lines of arbitrary intercept and slope

see ?abline

HTH

G
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
*  Note new Address, Telephone  Fax numbers from 6th April 2006  *
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson
ECRC  ENSIS  [t] +44 (0)20 7679 0522
UCL Department of Geography   [f] +44 (0)20 7679 0565
Pearson Building  [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street  [w] http://www.ucl.ac.uk/~ucfagls/cv/
London, UK.   [w] http://www.ucl.ac.uk/~ucfagls/
WC1E 6BT.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
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


Re: [R] Vertical Line on Plot

2006-05-25 Thread Peter Ehlers

Barry Rowlingson wrote:
 Peter Lauren wrote:
 
I was wondering what would be the best way to put a
vertical line on a graph made with plot().  I can get
an horizontal line by plotting a vector where every
element has the same value but it is not as clear how
a vertical line should be done.

 
 
   abline(v=42)
 
 you can use it for horizontal lines too: abline(h=42) and several other 
 things. See help(abline) for details.
 
 Barry
 

I don't wish to discourage new R users from asking questions in
this forum, but this seems like a good time to remind new R users
of the existence of some _very_ useful documentation:

1. As has just recently been mentioned again by Berton Gunter
in his periodic reminder, there exists a nice, concise ref-card at
  http://www.rpad.org/Rpad/Rpad-refcard.pdf

This would have led to abline() almost immediately (page 3).

2. 'An Introduction to R' is installed with R. Again, it would
have quickly led to abline() (section 12.2).

The help pages are great when you know what function you need.
The above two documents (and others on CRAN) help one to discover
what function might be needed.

Peter Ehlers

__
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