[R] Vertical Line on Plot
Gavin Simpson
gavin.simpson at ucl.ac.uk
Thu May 25 18:52:00 CEST 2006
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.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list