[R] Getting total bar's label & value labels in a barplot

Luca Meyer lucam1968 at gmail.com
Sun Jan 9 18:03:36 CET 2011


Hi,

I have been trying to get the label under the total column - i.e. a mean value of columns 2 to 6 - in a barplot I generate with this script:

t1 <- tapply(A, B, sum)
t1[8] <- mean(t1[2:6])
t1 <- as.table(t1)
barplot(t1, ylim=c(0,3000))
mtext("Var1", side = 1, line = 3)
mtext("Var2", side = 2, line = 3)

I have been trying to use

axis(1, at=1:8, labels=c("1","2","3","4","5","6","7","8"))

but I get labels not standing underneat the columns...can someone help me out on this one?

Also, I would like to plot onto each bar the corresponding numerical value - e.g. "1824" on the first bar, ecc...

Please notice that str(t1) would look like:

 Named num [1:8] 1824 2339 2492 2130 2360 ...
 - attr(*, "names")= chr [1:8] "1" "2" "3" "4" ...

Thanks,
Luca


Mr. Luca Meyer
www.lucameyer.com
IBM SPSS Statistics release 19.0.0
R version 2.12.1 (2010-12-16)
Mac OS X 10.6.5 (10H574) - kernel Darwin 10.5.0



More information about the R-help mailing list