Re: [R] Display values in piechart/barplot

From: Marc Schwartz (via MN) <>
Date: Fri 30 Sep 2005 - 03:01:54 EST

On Thu, 2005-09-29 at 14:34 +0200, Volker Rehbock wrote:
> Is it possible to automatically display the underlying values of a
> piechart/barplot in the graphic? If so, which package/function/argument do I
> need for it?
> Thanks,
> Volker

Using pie charts are not a particularly good way of displaying data, even though the pie() function is available in R. See ?pie for more information on this.

For barplots, the following provide two approaches:

# Place the bar values above the bars
# Note that I set 'ylim' to make room for 
# the text labels above the bars

vals <- 1:5
names(vals) <- LETTERS[1:5]
mp <- barplot(vals, ylim = c(0, 6))
text(mp, vals, labels = vals, pos = 3)

# Place the bar values below the x axis

vals <- 1:5
names(vals) <- LETTERS[1:5]
mp <- barplot(vals)
mtext(side = 1, at = mp, text = vals, line = 3)

Note that barplot() returns the bar midpoints, so you can use these values for annotation placement.

See ?barplot, ?text and ?mtext for more information.

HTH, Marc Schwartz mailing list PLEASE do read the posting guide! Received on Fri Sep 30 03:23:58 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:00:09 EST