Skip to content

add absolute value to bars in barplot

3 messages · soeren.vogel at eawag.ch, Philipp Pagel, Greg Snow

#
Hello,

r-help at r-project.orgbarplot(twcons.area,
   beside=T, col=c("green4", "blue", "red3", "gray"),
   xlab="estate",
   ylab="number of persons", ylim=c(0, 110),
   legend.text=c("treated", "mix", "untreated", "NA"))

produces a barplot very fine. In addition, I'd like to get the bars'  
absolute values on the top of the bars. How can I produce this in an  
easy way?

Thanks

S?ren
#
On Fri, Feb 27, 2009 at 01:32:45PM +0100, soeren.vogel at eawag.ch wrote:
barplot() returns a vector of midpoints so you can use text() to add the
annotation. There is an example in the manual page of barplot:

mp <- barplot(VADeaths)
tot <- colMeans(VADeaths)
text(mp, tot + 3, format(tot), xpd = TRUE, col = "blue")

cu
	Philipp
#
Note that putting numbers near the top of the bars (either inside or outside) tends to create 'fuzzy' tops to the bars that make it harder for the viewer to quickly interpret the graph.  If the numbers are important, put them in a table.  If you really need to have the numbers and graph together then look at alternatives (some type of combined table/graph) or put the numbers in a margin of the graph where they will not distract from the graph itself.