Skip to content

Display values in piechart/barplot

3 messages · Volker Rehbock, Marc Schwartz (via MN), Jim Lemon

#
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
#
On Thu, 2005-09-29 at 14:34 +0200, Volker Rehbock wrote:
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
#
Volker Rehbock wrote:
floating.pie and pie.labels in the plotrix package.

Jim