Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change width of bars in barchart (R)

Tags:

r

width

bar-chart

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.

like image 217
Stefanie Wind Avatar asked Apr 01 '13 20:04

Stefanie Wind


1 Answers

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)
like image 189
Josh O'Brien Avatar answered Nov 16 '22 00:11

Josh O'Brien