[R] Place independent labels between values on x-axis

Uwe Ligges ligges at statistik.tu-dortmund.de
Thu Feb 26 10:02:01 CET 2009



T.D.Rudolph wrote:
> I conducted a frequency averaging procedure which left me with the data frame
> below (Bin is an artifact of a cut() procedure and can be either
> as.character or as.factor):
> 
>            Bin     Freq
> 1  (-180,-160] 7.904032
> 2  (-160,-140] 5.547901
> 3  (-140,-120] 4.522542
> 4  (-120,-100] 4.784184
> 5   (-100,-80] 4.490083
> 6    (-80,-60] 4.754268
> 7    (-60,-40] 5.597407
> 8    (-40,-20] 5.964031
> 9      (-20,0] 7.266519
> 10      (0,20] 6.947202
> 11     (20,40] 6.168730
> 12     (40,60] 4.918232
> 13     (60,80] 4.638589
> 14    (80,100] 4.288087
> 15   (100,120] 4.091052
> 16   (120,140] 4.451199
> 17   (140,160] 5.869740
> 18   (160,180] 7.796204
> 
> I am able to present the data as a histogram using barplot(), but on the
> x-axis I would like to see the values that separate (i.e. that are located
> between) my various bins (i.e. seq(-180,180,20)).  Thus 0 would appear
> directly under the centre line that separates (-20,0] and (0,20], etc.
> 
> barplot(angledist$Freq, xlab="Turning Angle", ylab="Average frequency (%)",
> ylim=c(0,10))
> 
> ?names.arg, ?xlim don't seem to do it but I could be wrong....
> Tyler



Two comments:

1. In fact you probably want a histpgram on your un-cut()-ted data and 
specify breaks. A barplot seems to be misleading for originally 
continuous data.

2. You can suppress x-axis labels by specifying the argument xaxt="n" 
and add your own x-axis later on by a call to axis() which allows to 
specify the tick mark positions.

Uwe Ligges




More information about the R-help mailing list