Luca Meyer
2011-Jan-09 17:03 UTC
[R] Getting total bar's label & value labels in a barplot
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
David Winsemius
2011-Jan-10 01:47 UTC
[R] Getting total bar's label & value labels in a barplot
Try looking at the barplot function and notice that is should be returning values for the mid-points. You should use those instead of the at=values On Jan 9, 2011, at 12:03 PM, Luca Meyer wrote:> 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 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD Heritage Laboratories West Hartford, CT