[R] barplot(names.arg) versus axis(labels)

Siddique, Amer Amer.Siddique at ssa.gov
Fri Nov 7 21:29:46 CET 2003


Should I be able to use axis() on a barplot?  i have a data.frame, the first
3 values of which are:

> c[1:3,]
    median      mean
A1    56.5  58.50000
A61   73.0  73.00000
A62   63.0  63.00000

> str(c)
`data.frame':   19 obs. of  2 variables:
 $ median: num  56.5 73 63 161 51 55 44.5 22 54 49 ...
 $ mean  : num   58.5  73.0  63.0 161.0  47.5 ...

if I do barplot(median) and then try to label the bars with axis(), I get;

> axis(1,,labels=rownames(c),font=4,cex=1)
Error in axis(side, at, labels, tick, line, pos, outer, font, vfont, lty,  :

        location and label lengths differ, 5 != 19

even though 

barplot(median, names.arg=rownames(c)) works and

> length(rownames(c))
[1] 19

also when I attempt to place the value of the observation
 above the bar it does not space properly across all bars:

text(median,labels=median,pos=3,cex=0.6)

do i need to explicitly state an x-pos for the co-ord argument here?

Thanks,
Amer




More information about the R-help mailing list