How to display all x labels in R barplot?

user2760 picture user2760 · Apr 2, 2012 · Viewed 97.2k times · Source

This is a basic question but I am unable to find an answer. I am generating about 9 barplots within one panel and each barplot has about 12 bars. I am providing all the 12 labels in my input but R is naming only alternate bars. This is obviously due to to some default setting in R which needs to be changed but I am unable to find it.

Answer

IRTFM picture IRTFM · Apr 2, 2012

You may be able get all of the labels to appear if you use las=2 inside the plot() call. Otherwise, you will need to use xaxt="n" and then put the labels in with a separate call to axis(1, at= ..., labels=...).

Another method is to first collect the midpoints and then use text() with xpd and srt to control the degree of text rotation:

text(x=midpts, y=-2, names(DD), cex=0.8, srt=45, xpd=TRUE)

The y-value needs to be chosen using the coordinates in the plotted area.