[R] Adding Lines to Plot

Greg Snow Greg.Snow at intermountainmail.org
Mon Jul 10 21:02:22 CEST 2006

 There are a couple of different options that you can try (each
generalize a bit differently to other situations).

If you just want lines at the tick marks to go the entire width (and be
generated automatically to match the labels), then look at ?par and look
at 'tck', you can use this in the barplot call, or in a call to axis
after the fact.  If you want the bars on top then just issue another
call to barplot with add=T.

See abline and the h= option for drawing lines across the entire width.

See par and the 'usr' entry for how to find the user coordinates of the
edges of the plot (for adding lines by hand).

See the cnvrt.coords function in the TeachingDemos package for more
general conversions between coordinate systems (you can use this to draw
a line from half way across to the edge, or other aritrary locations,
probably overkill for your problem). 

The return value for barplot gives the center positions of the bars (the
heights match the data you input to barplot), see the first example in
the help for barplot.

Hope this helps,

Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of justin rapp
Sent: Saturday, July 08, 2006 1:05 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Adding Lines to Plot

This seems like a question that I should be able to answer on my own but
after looking at the documentation I cannot seem to find the correct

How do I add lines to a bar plot that extend from the vertical axis?
For example, my vertical axis is numbered in increments of 10 and I
would like these to go across the whole graph.

Also, is there a way to have R label the value of each bar so that I
know the value of each factor that is being plotted?

Thanks in advance.


R-help at stat.math.ethz.ch mailing list
PLEASE do read the posting guide!

More information about the R-help mailing list