Skip to content

Help on BarPlot

3 messages · Steve Sidney, Marc Schwartz, Thomas Roth (geb. Kaliwe)

#
on 02/09/2009 03:21 PM Steve Sidney wrote:
If the 'Z' scores are the typical standard deviation based continuous Z
scores, rather than a barplot, I would recommend a dotchart or point
based plot. Barplots are best suited for count/frequency based data. See
?dotchart.

With respect to the barplot, the key piece of information to know is
that barplot() returns the bar midpoints, which you need to know for
subsequent text placement. This is described in ?barplot.

Something like this should get you there:

# For reproducibility
set.seed(1)

# Generate a sample of LETTERS
L <- sample(LETTERS[1:5], 100, replace = TRUE)

# Create a frequency table
TL <- table(L)
L
 A  B  C  D  E
13 25 19 26 17

# Create the barplot, set ylim to make room for the text
# set names.arg so that nothing appears below the x axis
mp <- barplot(TL, ylim = c(0, 30), names.arg = NA)

# What's in mp?
[,1]
[1,]  0.7
[2,]  1.9
[3,]  3.1
[4,]  4.3
[5,]  5.5

# Now draw the text at x = mp; y = TL positions.
# Set 'pos' to move the values above the bars
text(mp, TL, labels = names(TL), pos = 3)

# If you wanted the counts above the bars instead of the labels:
text(mp, TL, labels = TL, pos = 3)

HTH,

Marc Schwartz
#
Hi,

#There are a lot of examples for barplot if you just type

example(barplot)

# i altered one slightly to put the values on top of each bar

mp <- barplot(VADeaths)     # default
#tot <- colMeans(VADeaths)   #changed this line
tot = colSums(VADeaths)    #wether you need max, min, mean , colSums 
will depend on your data
text(mp, tot + 4, format(tot), xpd = TRUE, col = "blue")


#you should be able to get it from here


Thomas




Steve Sidney schrieb: