[R] Putting value labels inside the bars of a bar plot

Paul Murrell p.murrell at auckland.ac.nz
Thu Nov 14 03:12:08 CET 2002


Hi


Tom Arnold wrote:
> 
> I'd like to label a bar plot with the actual value of each bar, inside the
> bar. I see that there are ways to plot arbitrary text, so I could do it
> 'manually', but this seems common enough that there's probably a simple
> solution. I don't see it in the high-level documentation for barplot, and
> haven't found it anywhere yet. How might this be done?


The trick is to know that barplot returns the x-location of the
midpoints of the bars.  Here's a simple example:

	x <- sample(seq(15, 30, 5))
	midpoints <- barplot(x)
	text(midpoints, 3, labels=x)

Paul
-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x5392
paul at stat.auckland.ac.nz
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list