[R] Labeling position barchart

Jim Lemon jim at bitwrit.com.au
Sat Nov 10 09:53:52 CET 2012


On 11/09/2012 10:33 PM, Geophagus wrote:
> Hi @ all,
> I try to set a labeling on simple barchart.
> I do it with the text function. I want to see values of the x axis
> (BE_AKT$ammo) above the bars.
> When I try the following code, the values are shown, but not in the correct
> position.
> They should be labeled 0.08 above the bars.
>
> text(BE_AKT$ammo, BE_AKT$ammo + 0.08, label = BE_AKT$ammo, family="Calibri")
>
Hi GeO,
At a rough guess, you want the _bottoms_ of the labels 0.08 user units 
above the tops of the bars. It is very unlikely that the values of 
BE_AKT$ammo (is that the 5.45 or the old 7.62?) will be valid for both x 
and y coordinates. What you probably want to do is collect the x 
positions from the initial plot:

xpos<-barplot(...)

then combine those with the y positions of your values for BE_AKT$ammo:

text(xpos,BE_AKT$ammo + 0.08,label=BE_AKT$ammo,family="Calibri",pos=3)

Notice that "pos=3" argument. This places the text above the 
coordinates. You can also do this with the "adj" argument.

Jim




More information about the R-help mailing list