8

I am wondering how to change the width of the bars in the barchart() function.

Here is the code:

rater1 <- c(0.75, 0.66, 0.73,   0.63)
barplot(rater1, ylim=c(0:1),axes = TRUE, names.arg = c("A", "B", "C", "D"), axisnames=TRUE, col="grey70")

Is it also possible to place value labels above the bars?

Thanks.

Stefanie Wind
  • 83
  • 1
  • 1
  • 3
  • Placing labels above the individual bars distorts the heights of the bars, sometimes called the "fuzzy bar" effect. It also manages to turn a perfectly good bar chart into a poorly laid out table with colorful background. If you feel the need to add the labels then consider if the chart is really accomplishing what it was intended for. A table may be more appropriate. If the bar chart works, but you feel your audience will want exact values then consider placing the labels clearly in the margin where they will not interfere with the visual interpretation of the bars. – Greg Snow Apr 02 '13 at 18:58

1 Answers1

15

From ?barplot:

space: the amount of space (as a fraction of the average bar width) left before each bar. May be given as a single number or one number per bar. [...]

So, for example, compare:

tN <- table(Ni <- stats::rpois(100, lambda = 5))
barplot(tN, col = rainbow(20))

barplot(tN, col = rainbow(20), space=0)

barplot(tN, col = rainbow(20), space=10)
Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
  • Thanks very much! Do you also know how to add value labels above the bars? – Stefanie Wind Apr 01 '13 at 20:16
  • @StefanieWind -- [Here is one example](http://stackoverflow.com/questions/12481430/how-to-display-the-frequency-at-the-top-of-each-factor-in-a-barplot-in-r/12483754#12483754). There are others here on SO which I'm sure you'll find with a bit of poking around using the search bar at the top right. Cheers. – Josh O'Brien Apr 01 '13 at 20:20