Message-ID: <1128013314.5402.30.camel@localhost.localdomain>
Date: 2005-09-29T17:01:54Z
From: Marc Schwartz (via MN)
Subject: Display values in piechart/barplot
In-Reply-To: <000701c5c4f2$2d591630$d636a986@mast405>
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