Hi, I couldn't find how to have the values written on the top of each bar in a barplot. When using hist(), it is possible to use labels=T, but this option does not seem to exist for barplot(). Is there a trick I could use to do that ? Thanks to all Luc
On 5/30/05, luc tardieu <luc_tardieu at yahoo.fr> wrote:> Hi, > > I couldn't find how to have the values written on the > top of each bar in a barplot. When using hist(), it is > possible to use labels=T, but this option does not > seem to exist for barplot(). > > Is there a trick I could use to do that ? > > Thanks to all >Here is an example you can modify: x <- c(44,56,34,35,44,51,55) nams <- LETTERS[1:7] bp <- barplot(x,horiz=T,col="light blue",xlim=c(0,60)) text(30,-1.25,xpd=NA,"Networks",cex=1.5) # x title text(-6,4,xpd=NA,"Research Areas",cex=1.5,srt=90) # y title text(x,bp,x,pos=4) # place numbers to right of bars text(0,bp,nams,cex=1.2,pos=4) # label bars right on the bars themselves
luc tardieu wrote:> Hi, > > I couldn't find how to have the values written on the > top of each bar in a barplot. When using hist(), it is > possible to use labels=T, but this option does not > seem to exist for barplot(). > > Is there a trick I could use to do that ? > > Thanks to all > > Luc > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >something like: x <- 1:3 #ensure some free space above the bar and remember midpoints: bmp <- barplot(x, ylim = c(0, 1.1*max(x))) text(bmp, x + .03*max(x), x) should do.
On 30 May 2005 at 15:19, luc tardieu wrote:> Hi, > > I couldn't find how to have the values written on the > top of each bar in a barplot. When using hist(), it is > possible to use labels=T, but this option does not > seem to exist for barplot().Hallo>From help pageValue: A numeric vector (or matrix, when 'beside = TRUE'), say 'mp', giving the coordinates of _all_ the bar midpoints drawn, useful for adding to the graph. e.g.> dat<-trunc(runif(5)*10) > dat[1] 5 7 1 9 5> bpl<-barplot(dat, ylim=c(0,10)) > text(bpl,dat+.2, dat)HTH Petr> > Is there a trick I could use to do that ? > > Thanks to all > > Luc > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz