[R] barplot and names.arg

Marc Schwartz MSchwartz at MedAnalytics.com
Fri Aug 13 16:46:57 CEST 2004


On Fri, 2004-08-13 at 09:22, Luis Rideau Cruz wrote:
> R-help
> 
> Is there any option to get closer the x-axis and names.arg from barplot?
> 
> Thank you

Using mtext() you can do something like the following:

data(VADeaths)

# Now place labels closer to the x axis
# set 'axisnames' to FALSE so the default
# labels are not drawn. Also note that barplot() 
# returns the bar midpoints, so set 'mp' to the return
# values
mp <- barplot(VADeaths, axisnames = FALSE)

# Now use mtext() for the axis labels
mtext(text = colnames(VADeaths), side = 1, at = mp, line = 0)

# clean up
rm(VADeaths)


You can adjust the 'line = 0' argument to move the labels closer to and
farther away from the axis.

HTH,

Marc Schwartz




More information about the R-help mailing list