[R] barplot(): X-Axis Labels

Marc Schwartz mschwartz at medanalytics.com
Tue Oct 15 04:59:35 CEST 2002


> -----Original Message-----
> Thank you all very much for your assistance. One more issue I do have
is
> creating a label for the x-axis. If I specificy xlab = "" within the
barplot(), it get
> overwritten by the category labels. I tried to add one below that with
text(
> locator( 1 ), "x-axis label" ), but it seems that it won't insert the
text below a
> certain threshold. Is there a way around this?
> Thanks again.
> 
> Jess

Jess,

Normally when drawing text outside the plot region, which is defined by
the box() around the barplot in this case, you need to use mtext() and
not text().

The generation of the 45 degree rotated axis labels in the code I posted
earlier "tricks" the text() command in drawing the labels outside the
plot region.  The x and y coordinate values that text() uses are based
upon the plot region area coordinates.

Add the following line to the end of the prior example code:

mtext("x-axis label", line = 3, side = 1)

It will get overwritten by the axis labels, so you will need to adjust
the "line = " argument to move the x axis label vertically to a position
that makes sense with your real data. 

The "line" argument starts at 0 (zero) near the x axis itself and
increases as you approach the bottom limit of the open graphics window.
If you go too high in "line = ", it will be drawn outside (below) the
visible window.  Thus, you may have to adjust the margin boundaries for
the window to provide additional room below the plot region.  You can do
this by using par("mar") before the barplot is drawn.

HTH.

Marc



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list