user2760 user2760 - 1 year ago 96
R Question

How to display all x labels in R barplot?

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.

42- 42-
Answer Source

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.