Skip to content
Prev 82686 / 398506 Next

Labeling a range of bars in barplot?

On Tue, 2005-12-13 at 10:53 +0000, Dan Bolser wrote:
Dan,

Here is a hint.

barplot() returns the bar midpoints:

mp <- barplot(sort(x, decreasing = TRUE))
[,1]
[1,]  0.7
[2,]  1.9
[3,]  3.1
[4,]  4.3
[5,]  5.5
[6,]  6.7

There will be one value in 'mp' for each bar in your series.

You can then use those values along the x axis to draw your line
segments under the bars as you require, based upon the cut points you
want to highlight.

To get the center of a given group of bars, you can use:

  mean(mp[start:end])

where 'start' and 'end' are the extreme bars in each of your groups.

Two other things that might be helpful. See ?cut and ?hist, noting the
output in the latter when 'plot = FALSE'.

HTH,

Marc Schwartz